Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 6, 2024
1 parent 6b90363 commit 7ca81f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions zninit/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _handle_args(args, kwargs, kwarg_names, cls_name):
TypeError
if more positional arguments are given than keyword arguments
if a keyword argument is given multiple times
"""
if len(args) > len(kwarg_names):
raise TypeError(
Expand Down Expand Up @@ -111,6 +112,7 @@ def get_auto_init( # noqa: C901
typically this is Node.__init__
allow_args: bool
allow args in the __init__. Otherwise only kwargs are allowed
"""
kwargs_no_default = [] if kwargs_no_default is None else kwargs_no_default
kwargs_with_default = {} if kwargs_with_default is None else kwargs_with_default
Expand Down Expand Up @@ -143,9 +145,9 @@ def auto_init(self, *args, **kwargs): # noqa: C901
if kwarg_name not in priority_kwargs:
required_keys.append(kwarg_name)

init_kwargs.update({
name: kwargs.pop(name, value) for name, value in kwargs_with_default.items()
})
init_kwargs.update(
{name: kwargs.pop(name, value) for name, value in kwargs_with_default.items()}
)
super_init(self, **kwargs) # call the super_init explicitly instead of super
# must call the super_init first e.g. it is required to set the node_name

Expand Down Expand Up @@ -238,6 +240,7 @@ def _get_auto_init_signature(cls) -> typing.Tuple[list, dict, list]:
kwargs_with_default: dict
a dict of {name: default} that will be converted to kwargs
signature_params: inspect.Parameter
"""
signature_params = []
cls_annotations = cls.__annotations__ # pylint: disable=no-member
Expand Down Expand Up @@ -277,6 +280,7 @@ class ZnInit: # pylint: disable=R0903
A list of kwargs that should be prioritized in the __init__.
These kwargs will be set in the given order before
the other args / kwargs are set.
"""

init_descriptors: typing.List[Descriptor] = [Descriptor]
Expand Down Expand Up @@ -305,6 +309,7 @@ def __init__(self):
Raises
------
TypeError: ZnInit.__init__() got an unexpected keyword argument ...
"""

def __init_subclass__(cls, allow_args: bool = True, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions zninit/descriptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(
on_setattr: Callable, default=None
A callable that is run whenever an attribute is set via 'class.myattr = value'
or 'setattr(class, "mattr", value)'.
"""
self._default = default
self._owner = owner
Expand Down Expand Up @@ -140,6 +141,7 @@ def annotation(self):
------
KeyError:
if type checking and the descriptor has no annotation.
"""
try:
annotations_ = self.owner.__annotations__
Expand All @@ -164,6 +166,7 @@ def __get__(self, instance, owner=None):
Raises
------
AttributeError: if the value is not in the instance.__dict__ or in self.default
"""
self._instance = instance
if instance is None:
Expand Down

0 comments on commit 7ca81f4

Please sign in to comment.