Skip to content

Commit

Permalink
Merge 7ca81f4 into 4f7b349
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed May 6, 2024
2 parents 4f7b349 + 7ca81f4 commit ab5df82
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -21,13 +21,13 @@ repos:
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.4.2
hooks:
- id: black
additional_dependencies: [".[jupyter]"]
types_or: [python, pyi, jupyter]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/codespell-project/codespell
Expand All @@ -37,7 +37,7 @@ repos:
additional_dependencies: ["tomli"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.1.6'
rev: 'v0.4.3'
hooks:
- id: ruff
args: ['--fix']
Expand Down
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 ab5df82

Please sign in to comment.