Skip to content

Commit

Permalink
refactor!: mark some arguments as positional-only as of Python 3.8+ (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan authored Dec 15, 2024
1 parent e81958d commit 47e8941
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 258 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ repos:
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
rev: v19.1.5
hooks:
- id: clang-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
rev: v0.8.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

-
- Mark some arguments as positional-only as of Python 3.8+ by [@XuehaiPan](https://github.com/XuehaiPan) in [#178](https://github.com/metaopt/optree/pull/178).

### Fixed

Expand Down
77 changes: 44 additions & 33 deletions optree/_C.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ GLIBCXX_USE_CXX11_ABI: bool

def flatten(
tree: PyTree[T],
/,
leaf_predicate: Callable[[T], bool] | None = None,
node_is_leaf: bool = False,
namespace: str = '',
) -> tuple[list[T], PyTreeSpec]: ...
def flatten_with_path(
tree: PyTree[T],
/,
leaf_predicate: Callable[[T], bool] | None = None,
node_is_leaf: bool = False,
namespace: str = '',
Expand All @@ -63,29 +65,32 @@ def make_none(
) -> PyTreeSpec: ...
def make_from_collection(
collection: Collection[PyTreeSpec],
/,
node_is_leaf: bool = False,
namespace: str = '',
) -> PyTreeSpec: ...
def is_leaf(
obj: T,
/,
leaf_predicate: Callable[[T], bool] | None = None,
node_is_leaf: bool = False,
namespace: str = '',
) -> bool: ...
def all_leaves(
iterable: Iterable[T],
/,
leaf_predicate: Callable[[T], bool] | None = None,
node_is_leaf: bool = False,
namespace: str = '',
) -> bool: ...
def is_namedtuple(obj: object | type) -> bool: ...
def is_namedtuple_instance(obj: object) -> bool: ...
def is_namedtuple_class(cls: type) -> bool: ...
def namedtuple_fields(obj: tuple | type[tuple]) -> tuple[str, ...]: ...
def is_structseq(obj: object | type) -> bool: ...
def is_structseq_instance(obj: object) -> bool: ...
def is_structseq_class(cls: type) -> bool: ...
def structseq_fields(obj: tuple | type[tuple]) -> tuple[str, ...]: ...
def is_namedtuple(obj: object | type, /) -> bool: ...
def is_namedtuple_instance(obj: object, /) -> bool: ...
def is_namedtuple_class(cls: type, /) -> bool: ...
def namedtuple_fields(obj: tuple | type[tuple], /) -> tuple[str, ...]: ...
def is_structseq(obj: object | type, /) -> bool: ...
def is_structseq_instance(obj: object, /) -> bool: ...
def is_structseq_class(cls: type, /) -> bool: ...
def structseq_fields(obj: tuple | type[tuple], /) -> tuple[str, ...]: ...

class PyTreeKind(enum.IntEnum):
CUSTOM = 0 # a custom type
Expand All @@ -108,61 +113,66 @@ class PyTreeSpec:
namespace: str
type: builtins.type | None
kind: PyTreeKind
def unflatten(self, leaves: Iterable[T]) -> PyTree[T]: ...
def flatten_up_to(self, full_tree: PyTree[T]) -> list[PyTree[T]]: ...
def broadcast_to_common_suffix(self, other: Self) -> Self: ...
def unflatten(self, leaves: Iterable[T], /) -> PyTree[T]: ...
def flatten_up_to(self, full_tree: PyTree[T], /) -> list[PyTree[T]]: ...
def broadcast_to_common_suffix(self, other: Self, /) -> Self: ...
def transform(
self,
/,
f_node: Callable[[Self], Self] | None = None,
f_leaf: Callable[[Self], Self] | None = None,
) -> Self: ...
def compose(self, inner_treespec: Self) -> Self: ...
def compose(self, inner_treespec: Self, /) -> Self: ...
def walk(
self,
leaves: Iterable[T],
/,
f_node: Callable[[builtins.type, MetaData, tuple[U, ...]], U] | None = None,
f_leaf: Callable[[T], U] | None = None,
) -> U: ...
def paths(self) -> list[tuple[Any, ...]]: ...
def accessors(self) -> list[PyTreeAccessor]: ...
def entries(self) -> list[Any]: ...
def entry(self, index: int) -> Any: ...
def children(self) -> list[Self]: ...
def child(self, index: int) -> Self: ...
def one_level(self) -> Self | None: ...
def is_leaf(self, *, strict: bool = True) -> bool: ...
def is_one_level(self) -> bool: ...
def is_prefix(self, other: Self, *, strict: bool = False) -> bool: ...
def is_suffix(self, other: Self, *, strict: bool = False) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __le__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def __len__(self) -> int: ...
def paths(self, /) -> list[tuple[Any, ...]]: ...
def accessors(self, /) -> list[PyTreeAccessor]: ...
def entries(self, /) -> list[Any]: ...
def entry(self, index: int, /) -> Any: ...
def children(self, /) -> list[Self]: ...
def child(self, index: int, /) -> Self: ...
def one_level(self, /) -> Self | None: ...
def is_leaf(self, /, *, strict: bool = True) -> bool: ...
def is_one_level(self, /) -> bool: ...
def is_prefix(self, other: Self, /, *, strict: bool = False) -> bool: ...
def is_suffix(self, other: Self, /, *, strict: bool = False) -> bool: ...
def __eq__(self, other: object, /) -> bool: ...
def __ne__(self, other: object, /) -> bool: ...
def __lt__(self, other: object, /) -> bool: ...
def __le__(self, other: object, /) -> bool: ...
def __gt__(self, other: object, /) -> bool: ...
def __ge__(self, other: object, /) -> bool: ...
def __hash__(self, /) -> int: ...
def __len__(self, /) -> int: ...

class PyTreeIter(Iterator[T]):
def __init__(
self,
tree: PyTree[T],
/,
leaf_predicate: Callable[[T], bool] | None = None,
node_is_leaf: bool = False,
namespace: str = '',
) -> None: ...
def __iter__(self) -> Self: ...
def __next__(self) -> T: ...
def __iter__(self, /) -> Self: ...
def __next__(self, /) -> T: ...

def register_node(
cls: type[Collection[T]],
/,
flatten_func: FlattenFunc[T],
unflatten_func: UnflattenFunc[T],
path_entry_type: type[PyTreeEntry],
namespace: str = '',
) -> None: ...
def unregister_node(
cls: type,
/,
namespace: str = '',
) -> None: ...
def is_dict_insertion_ordered(
Expand All @@ -171,5 +181,6 @@ def is_dict_insertion_ordered(
) -> bool: ...
def set_dict_insertion_ordered(
mode: bool,
/,
namespace: str = '',
) -> None: ...
Loading

0 comments on commit 47e8941

Please sign in to comment.