diff --git a/pyproject.toml b/pyproject.toml index f5898b1..d5a09ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,31 +59,27 @@ include = [ [tool.hatch.envs.default] dependencies = [ - "black==23.3.0", - "flake8-docstrings==1.7.0", - "flake8-pyproject", - "flake8==5.0.4", - "pylint==2.14.5", + "ruff==0.4.7", "pytest-cov==4.0.0", "pytest==7.2.0", ] [tool.hatch.envs.default.scripts] tests = ["unit-tests", "linters"] -unit-tests = "pytest --cov=spec_classes --cov-report=term-missing --cov-report=xml -vv {args} tests" +unit-tests = "pytest --cov=spec_classes --cov-report=term-missing --cov-report=xml -vv {args:tests}" linters = [ - "flake8 spec_classes tests", - "pylint spec_classes", - "black --check spec_classes tests", + "ruff check", + "ruff format --check", ] -format = "black spec_classes tests" +format = "ruff format spec_classes tests" [[tool.hatch.envs.test.matrix]] python = ["37", "38", "39", "310", "311", "312"] # Linting configuration -[tool.flake8] +[tool.ruff.lint] +select = ["E", "F", "W", "I", "PL"] ignore = [ "C901", "D100", @@ -98,41 +94,8 @@ ignore = [ "D400", "D401", "D413", - "E128", "E501", "F405", - "W503", - "W504", -] -max-complexity = 10 -application-import-names = "spec_classes" - -[tool.pylint."MESSAGES CONTROL"] -disable = [ - "assignment-from-no-return", - "cyclic-import", - "duplicate-code", - "exec-used", - "fixme", - "import-outside-toplevel", - "invalid-name", - "invalid-overridden-method", - "line-too-long", - "missing-docstring", - "no-member", - "protected-access", - "too-few-public-methods", - "too-many-arguments", - "too-many-branches", - "too-many-instance-attributes", - "too-many-lines", - "too-many-locals", - "too-many-nested-blocks", - "too-many-public-methods", - "too-many-return-statements", - "too-many-statements", - "ungrouped-imports", - "unused-argument", - "unused-wildcard-import", - "wildcard-import", + "PLR09", + "PLR2004", ] diff --git a/spec_classes/__init__.py b/spec_classes/__init__.py index cf76462..f68bc92 100644 --- a/spec_classes/__init__.py +++ b/spec_classes/__init__.py @@ -2,15 +2,15 @@ from .errors import FrozenInstanceError from .spec_class import spec_class from .types import ( - spec_property, - classproperty, + EMPTY, + MISSING, + SENTINEL, Alias, - DeprecatedAlias, Attr, AttrProxy, - MISSING, - EMPTY, - SENTINEL, + DeprecatedAlias, + classproperty, + spec_property, ) __author__ = "Matthew Wardrop" diff --git a/spec_classes/collections/base.py b/spec_classes/collections/base.py index 6596ed3..540cce0 100644 --- a/spec_classes/collections/base.py +++ b/spec_classes/collections/base.py @@ -3,7 +3,7 @@ from typing import Any, Callable, Dict, List, Type from spec_classes.methods.base import AttrMethodDescriptor -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.mutation import mutate_value, protect_via_deepcopy from spec_classes.utils.type_checking import ( check_type, @@ -164,25 +164,21 @@ def prepare(self): return self @abstractmethod - def _prepare_items(self): - ... # pragma: no cover + def _prepare_items(self): ... # pragma: no cover @abstractmethod - def _extractor(self, value_or_index, raise_if_missing=False) -> IndexedItem: - ... # pragma: no cover + def _extractor( + self, value_or_index, raise_if_missing=False + ) -> IndexedItem: ... # pragma: no cover @abstractmethod - def _inserter(self, index, item): - ... # pragma: no cover + def _inserter(self, index, item): ... # pragma: no cover @abstractmethod - def add_item(self, item): - ... # pragma: no cover + def add_item(self, item): ... # pragma: no cover @abstractmethod - def transform_item(self, value_or_index, transform): - ... # pragma: no cover + def transform_item(self, value_or_index, transform): ... # pragma: no cover @abstractmethod - def remove_item(self, value_or_index): - ... # pragma: no cover + def remove_item(self, value_or_index): ... # pragma: no cover diff --git a/spec_classes/collections/mappings.py b/spec_classes/collections/mappings.py index 3ab3ac4..5a017b2 100644 --- a/spec_classes/collections/mappings.py +++ b/spec_classes/collections/mappings.py @@ -61,9 +61,7 @@ def add_items(self, items: Mapping): self.add_item(k, v) return self - def transform_item( - self, key, transform, *, attr_transforms=None - ): # pylint: disable=arguments-renamed,arguments-differ + def transform_item(self, key, transform, *, attr_transforms=None): # pylint: disable=arguments-renamed,arguments-differ return self._mutate_collection( value_or_index=key, extractor=self._extractor, diff --git a/spec_classes/collections/sequences.py b/spec_classes/collections/sequences.py index 92d7aad..e0b664d 100644 --- a/spec_classes/collections/sequences.py +++ b/spec_classes/collections/sequences.py @@ -107,9 +107,7 @@ def transform_item( require_pre_existent=True, ) - def remove_item( - self, value_or_index, *, by_index=MISSING - ): # pylint: disable=arguments-differ + def remove_item(self, value_or_index, *, by_index=MISSING): # pylint: disable=arguments-differ index, _ = self._extractor( value_or_index, by_index=by_index, raise_if_missing=True ) diff --git a/spec_classes/collections/sets.py b/spec_classes/collections/sets.py index f08e27a..f106cae 100644 --- a/spec_classes/collections/sets.py +++ b/spec_classes/collections/sets.py @@ -45,9 +45,7 @@ def _inserter(self, index, item, replace=True): # pylint: disable=arguments-dif self.collection.discard(index) self.collection.add(item) - def add_item( - self, item, *, value_or_index=MISSING, replace=True, attrs=None - ): # pylint: disable=arguments-differ + def add_item(self, item, *, value_or_index=MISSING, replace=True, attrs=None): # pylint: disable=arguments-differ return self._mutate_collection( value_or_index=value_or_index, extractor=self._extractor, @@ -67,9 +65,7 @@ def add_items(self, items: Iterable): self.add_item(item) return self - def transform_item( - self, item, transform, *, attr_transforms=None - ): # pylint: disable=arguments-renamed,arguments-differ + def transform_item(self, item, transform, *, attr_transforms=None): # pylint: disable=arguments-renamed,arguments-differ return self._mutate_collection( value_or_index=item, extractor=self._extractor, diff --git a/spec_classes/methods/base.py b/spec_classes/methods/base.py index cc9abe1..47db79c 100644 --- a/spec_classes/methods/base.py +++ b/spec_classes/methods/base.py @@ -64,12 +64,10 @@ def method(self) -> Callable: @property @abstractmethod - def method_name(self) -> str: - ... # pragma: no cover + def method_name(self) -> str: ... # pragma: no cover @abstractmethod - def build_method(self) -> Callable: - ... # pragma: no cover + def build_method(self) -> Callable: ... # pragma: no cover class AttrMethodDescriptor(MethodDescriptor): # pylint: disable=abstract-method diff --git a/spec_classes/methods/collections/mappings.py b/spec_classes/methods/collections/mappings.py index 9b608a6..f9bba59 100644 --- a/spec_classes/methods/collections/mappings.py +++ b/spec_classes/methods/collections/mappings.py @@ -2,7 +2,7 @@ from inspect import Parameter from typing import Any, Callable, Dict, TypeVar, Union -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.method_builder import MethodBuilder from spec_classes.utils.mutation import mutate_attr from spec_classes.utils.type_checking import type_label diff --git a/spec_classes/methods/collections/sequences.py b/spec_classes/methods/collections/sequences.py index 08cdad6..56a6c49 100644 --- a/spec_classes/methods/collections/sequences.py +++ b/spec_classes/methods/collections/sequences.py @@ -2,7 +2,7 @@ from inspect import Parameter from typing import Any, Callable, Dict, Union -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.method_builder import MethodBuilder from spec_classes.utils.mutation import mutate_attr from spec_classes.utils.type_checking import type_label diff --git a/spec_classes/methods/collections/sets.py b/spec_classes/methods/collections/sets.py index c875fb8..6af8243 100644 --- a/spec_classes/methods/collections/sets.py +++ b/spec_classes/methods/collections/sets.py @@ -2,7 +2,7 @@ from inspect import Parameter from typing import Any, Callable, Dict, Union -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.method_builder import MethodBuilder from spec_classes.utils.mutation import mutate_attr from spec_classes.utils.type_checking import type_label diff --git a/spec_classes/methods/core.py b/spec_classes/methods/core.py index 273fd50..9e91dfc 100644 --- a/spec_classes/methods/core.py +++ b/spec_classes/methods/core.py @@ -8,7 +8,7 @@ from spec_classes.errors import FrozenInstanceError from spec_classes.methods.scalar import WithAttrMethod -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.method_builder import MethodBuilder from spec_classes.utils.mutation import ( invalidate_attrs, diff --git a/spec_classes/methods/scalar.py b/spec_classes/methods/scalar.py index 293b6d7..60d6479 100644 --- a/spec_classes/methods/scalar.py +++ b/spec_classes/methods/scalar.py @@ -8,7 +8,7 @@ from cached_property import cached_property from lazy_object_proxy import Proxy -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from spec_classes.utils.method_builder import MethodBuilder from spec_classes.utils.mutation import mutate_attr, mutate_value, prepare_attr_value diff --git a/spec_classes/spec_class.py b/spec_classes/spec_class.py index 0427c87..dd7b809 100644 --- a/spec_classes/spec_class.py +++ b/spec_classes/spec_class.py @@ -5,14 +5,15 @@ import warnings from collections import defaultdict from typing import Any, Callable, Dict, Iterable, Mapping, Optional, Type, Union -from typing_extensions import dataclass_transform from cached_property import cached_property +from typing_extensions import dataclass_transform -from spec_classes.methods import core as core_methods, SCALAR_METHODS, TOPLEVEL_METHODS +from spec_classes.methods import SCALAR_METHODS, TOPLEVEL_METHODS +from spec_classes.methods import core as core_methods from spec_classes.utils.weakref_cache import WeakRefCache -from .types import Attr, MISSING +from .types import MISSING, Attr @dataclass_transform() @@ -265,7 +266,7 @@ def bootstrap(self, spec_cls: type): annotation_namespace = {spec_cls.__name__: spec_cls, **vars(spec_cls)} if hasattr(spec_cls, "ANNOTATION_TYPES"): spec_annotation_types = spec_cls.ANNOTATION_TYPES - if hasattr(spec_annotation_types, "__call__"): + if callable(spec_annotation_types): spec_annotation_types = spec_cls.ANNOTATION_TYPES() if isinstance(spec_annotation_types, Mapping): annotation_namespace.update(spec_annotation_types) diff --git a/spec_classes/types/__init__.py b/spec_classes/types/__init__.py index b83ff7e..1b49db0 100644 --- a/spec_classes/types/__init__.py +++ b/spec_classes/types/__init__.py @@ -2,8 +2,8 @@ from .attr import Attr from .attr_proxy import AttrProxy from .keyed import KeyedList, KeyedSet -from .missing import MISSING, EMPTY, SENTINEL -from .spec_property import spec_property, classproperty +from .missing import EMPTY, MISSING, SENTINEL +from .spec_property import classproperty, spec_property from .validated import ValidatedType, bounded, validated __all__ = ( diff --git a/spec_classes/types/attr.py b/spec_classes/types/attr.py index 8c255be..aa814af 100644 --- a/spec_classes/types/attr.py +++ b/spec_classes/types/attr.py @@ -5,7 +5,7 @@ import functools import inspect from collections.abc import MutableMapping, MutableSequence, MutableSet -from typing import Any, Callable, Iterable, Optional, TYPE_CHECKING, Type +from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, Type from cached_property import cached_property diff --git a/spec_classes/types/keyed.py b/spec_classes/types/keyed.py index fe41daf..5dbf249 100644 --- a/spec_classes/types/keyed.py +++ b/spec_classes/types/keyed.py @@ -93,9 +93,7 @@ def __spec_class_check_type__(cls, instance: Any, type_: Type) -> bool: return True -class KeyedList( - Generic[ItemType, KeyType], MutableSequence, KeyedBase -): # pylint: disable=too-many-ancestors +class KeyedList(Generic[ItemType, KeyType], MutableSequence, KeyedBase): # pylint: disable=too-many-ancestors """ A list-like object that can also look up items by key. The computational complexity for list-like operations is the same as the base `list` class, @@ -221,9 +219,7 @@ def __repr__(self): return f"{type_label(self._type)}({repr(self._list)})" -class KeyedSet( - Generic[ItemType, KeyType], MutableSet, KeyedBase -): # pylint: disable=too-many-ancestors +class KeyedSet(Generic[ItemType, KeyType], MutableSet, KeyedBase): # pylint: disable=too-many-ancestors """ A set-like object that can also look up items by key. The computational complexity for set-like operations is the same as the base `set` class, diff --git a/spec_classes/types/spec_property.py b/spec_classes/types/spec_property.py index b2d7a6f..915f466 100644 --- a/spec_classes/types/spec_property.py +++ b/spec_classes/types/spec_property.py @@ -136,16 +136,13 @@ def _qualified_name(self): return f"{self.owner.__name__ if self.owner else ''}.{self.attr_name or ''}" @abstractmethod - def __get__(self, obj, objtype=None): - ... # pragma: no cover + def __get__(self, obj, objtype=None): ... # pragma: no cover @abstractmethod - def __set__(self, obj, value): - ... # pragma: no cover + def __set__(self, obj, value): ... # pragma: no cover @abstractmethod - def __delete__(self, obj): - ... # pragma: no cover + def __delete__(self, obj): ... # pragma: no cover class spec_property(_spec_property_base): diff --git a/spec_classes/types/validated.py b/spec_classes/types/validated.py index cffff90..4381f54 100644 --- a/spec_classes/types/validated.py +++ b/spec_classes/types/validated.py @@ -35,8 +35,7 @@ def __new__(cls, *args, **kwargs): @classmethod @abstractmethod - def validate(cls, obj: Any) -> bool: - ... # pragma: no cover + def validate(cls, obj: Any) -> bool: ... # pragma: no cover def validated( diff --git a/spec_classes/utils/mutation.py b/spec_classes/utils/mutation.py index 129bb5e..b0a9943 100644 --- a/spec_classes/utils/mutation.py +++ b/spec_classes/utils/mutation.py @@ -3,6 +3,7 @@ import copyreg import functools import inspect +import sys from threading import RLock from types import ModuleType from typing import Any, Callable, Dict, Optional, Set, Type, Union @@ -10,7 +11,7 @@ from lazy_object_proxy import Proxy from spec_classes.errors import FrozenInstanceError -from spec_classes.types import Attr, MISSING +from spec_classes.types import MISSING, Attr from .type_checking import check_type, type_label @@ -351,7 +352,8 @@ def _get_function_args(function, attrs): builtins, function.__name__, None ): return set() - function = getattr(function, "__init__", function) + if not inspect.isfunction(function) and not inspect.ismethod(function): + function = getattr(function, "__init__", function) if function is object.__init__: return set() # Otherwise, lookup signature and annotate function with args. @@ -361,9 +363,7 @@ def _get_function_args(function, attrs): except AttributeError: try: parameters = inspect.signature(function).parameters - except ( - ValueError - ): # pragma: no cover; Python 3.7 and newer raise a ValueError for C functions + except ValueError: # pragma: no cover; Python 3.7 and newer raise a ValueError for C functions parameters = {} if ( parameters @@ -372,8 +372,6 @@ def _get_function_args(function, attrs): return set(attrs or {}) try: function.__spec_class_args__ = set(parameters) - except ( - AttributeError - ): # pragma: no cover; this is a *very* rare edge-case affecting functions defined in C. + except AttributeError: # pragma: no cover; this is a *very* rare edge-case affecting functions defined in C. return set(parameters) return function.__spec_class_args__ diff --git a/spec_classes/utils/type_checking.py b/spec_classes/utils/type_checking.py index 41523fe..4ff7480 100644 --- a/spec_classes/utils/type_checking.py +++ b/spec_classes/utils/type_checking.py @@ -11,7 +11,9 @@ TypeVar, Union, _GenericAlias, -) # pylint: disable=protected-access +) + +# pylint: disable=protected-access from typing_extensions import Literal as LiteralExtension try: diff --git a/tests/collections/test_mappings.py b/tests/collections/test_mappings.py index cef1b1a..ffeade8 100644 --- a/tests/collections/test_mappings.py +++ b/tests/collections/test_mappings.py @@ -3,7 +3,7 @@ import pytest -from spec_classes import Attr, MISSING, spec_class +from spec_classes import MISSING, Attr, spec_class from spec_classes.collections import MappingMutator diff --git a/tests/collections/test_sequences.py b/tests/collections/test_sequences.py index 4f135ec..df34d19 100644 --- a/tests/collections/test_sequences.py +++ b/tests/collections/test_sequences.py @@ -3,7 +3,7 @@ import pytest -from spec_classes import Attr, MISSING, spec_class +from spec_classes import MISSING, Attr, spec_class from spec_classes.collections import SequenceMutator diff --git a/tests/collections/test_sets.py b/tests/collections/test_sets.py index 75a1d80..66c5107 100644 --- a/tests/collections/test_sets.py +++ b/tests/collections/test_sets.py @@ -3,7 +3,7 @@ import pytest -from spec_classes import Attr, MISSING, spec_class +from spec_classes import MISSING, Attr, spec_class from spec_classes.collections import SetMutator from spec_classes.types import KeyedSet diff --git a/tests/methods/test_collections_sequences.py b/tests/methods/test_collections_sequences.py index 46952c4..8753cef 100644 --- a/tests/methods/test_collections_sequences.py +++ b/tests/methods/test_collections_sequences.py @@ -198,16 +198,12 @@ def test_with(self, spec_cls, unkeyed_spec_cls): [unkeyed, unkeyed, unkeyed] ).without_spec_list_item(unkeyed).without_spec_list_item( -1 - ).spec_list_items == [ - unkeyed - ] + ).spec_list_items == [unkeyed] assert spec.with_spec_list_items( [unkeyed, unkeyed, unkeyed] ).without_spec_list_item(unkeyed).without_spec_list_item( -1, _by_index=True - ).spec_list_items == [ - unkeyed - ] + ).spec_list_items == [unkeyed] def test_update(self, spec_cls, unkeyed_spec_cls, keyed_spec_cls): spec = spec_cls( diff --git a/tests/methods/test_collections_sets.py b/tests/methods/test_collections_sets.py index ee75ac8..30108ff 100644 --- a/tests/methods/test_collections_sets.py +++ b/tests/methods/test_collections_sets.py @@ -157,12 +157,18 @@ def test_update(self, spec_cls, keyed_spec_cls): spec.update_keyed_spec_set_item( "a", keyed_spec_cls("c") ).keyed_spec_set_items["a"] - spec.update_keyed_spec_set_item("a", nested_scalar=100).keyed_spec_set_items[ - "a" - ].nested_scalar == 100 - spec.update_keyed_spec_set_item( - "a", nested_scalar=100, _if=False - ).keyed_spec_set_items["a"].nested_scalar == 1 + assert ( + spec.update_keyed_spec_set_item("a", nested_scalar=100) + .keyed_spec_set_items["a"] + .nested_scalar + == 100 + ) + assert ( + spec.update_keyed_spec_set_item("a", nested_scalar=100, _if=False) + .keyed_spec_set_items["a"] + .nested_scalar + == 1 + ) # Check that mutations in key work fine assert set( diff --git a/tests/test_spec_class.py b/tests/test_spec_class.py index b050ef8..eaa23e7 100644 --- a/tests/test_spec_class.py +++ b/tests/test_spec_class.py @@ -11,7 +11,7 @@ import pytest -from spec_classes import Attr, FrozenInstanceError, MISSING, spec_class, spec_property +from spec_classes import MISSING, Attr, FrozenInstanceError, spec_class, spec_property from spec_classes.spec_class import SpecClassMetadata, _SpecClassMetadataPlaceholder @@ -201,18 +201,21 @@ def test_spec_methods(self, spec_cls): ).strip() ) - assert spec_cls( - key="key", - list_values=[1, 2, 3], - dict_values={"a": 1, "b": 2}, - recursive=spec_cls(key="nested"), - set_values={ - "a" - }, # sets are unordered, so we use one item to guarantee order - ).__repr__(indent=False) == ( - "Spec(key='key', scalar=MISSING, list_values=[1, 2, 3], dict_values={'a': 1, 'b': 2}, set_values={'a'}, " - "spec=MISSING, spec_list_items=MISSING, spec_dict_items=MISSING, keyed_spec_list_items=MISSING, keyed_spec_dict_items=MISSING, " - "keyed_spec_set_items=MISSING, recursive=Spec(key='nested', ...))" + assert ( + spec_cls( + key="key", + list_values=[1, 2, 3], + dict_values={"a": 1, "b": 2}, + recursive=spec_cls(key="nested"), + set_values={ + "a" + }, # sets are unordered, so we use one item to guarantee order + ).__repr__(indent=False) + == ( + "Spec(key='key', scalar=MISSING, list_values=[1, 2, 3], dict_values={'a': 1, 'b': 2}, set_values={'a'}, " + "spec=MISSING, spec_list_items=MISSING, spec_dict_items=MISSING, keyed_spec_list_items=MISSING, keyed_spec_dict_items=MISSING, " + "keyed_spec_set_items=MISSING, recursive=Spec(key='nested', ...))" + ) ) with pytest.raises( diff --git a/tests/types/test_alias.py b/tests/types/test_alias.py index 206af2c..46e9a48 100644 --- a/tests/types/test_alias.py +++ b/tests/types/test_alias.py @@ -2,7 +2,7 @@ import pytest -from spec_classes import Alias, DeprecatedAlias, MISSING, spec_class +from spec_classes import MISSING, Alias, DeprecatedAlias, spec_class def test_alias(): diff --git a/tests/types/test_attr.py b/tests/types/test_attr.py index 5aaed03..1c80a8d 100644 --- a/tests/types/test_attr.py +++ b/tests/types/test_attr.py @@ -4,7 +4,7 @@ import pytest -from spec_classes import Attr, MISSING, spec_class +from spec_classes import MISSING, Attr, spec_class from spec_classes.collections import SequenceMutator @@ -30,7 +30,7 @@ def test_from_attr_value(self): ) a = Attr.from_attr_value("attr", f) assert a.name == "attr" - for attr in { + for attr in ( "default", "default_factory", "init", @@ -38,7 +38,7 @@ def test_from_attr_value(self): "compare", "hash", "metadata", - }: + ): a_value = getattr(a, attr) f_value = getattr(f, attr) assert ( diff --git a/tests/types/test_attr_proxy.py b/tests/types/test_attr_proxy.py index 27743d2..081ba3c 100644 --- a/tests/types/test_attr_proxy.py +++ b/tests/types/test_attr_proxy.py @@ -2,7 +2,7 @@ import pytest -from spec_classes import AttrProxy, MISSING, spec_class +from spec_classes import MISSING, AttrProxy, spec_class @pytest.mark.filterwarnings("ignore::DeprecationWarning") diff --git a/tests/types/test_missing.py b/tests/types/test_missing.py index 94fc5c5..bdd1a60 100644 --- a/tests/types/test_missing.py +++ b/tests/types/test_missing.py @@ -1,6 +1,6 @@ import copy -from spec_classes.types.missing import MISSING, EMPTY, SENTINEL +from spec_classes.types.missing import EMPTY, MISSING, SENTINEL def test_missing(): diff --git a/tests/types/test_spec_property.py b/tests/types/test_spec_property.py index 48025a2..09a9365 100644 --- a/tests/types/test_spec_property.py +++ b/tests/types/test_spec_property.py @@ -2,7 +2,7 @@ import pytest -from spec_classes import spec_class, spec_property, classproperty +from spec_classes import classproperty, spec_class, spec_property from spec_classes.errors import NestedAttributeError diff --git a/tests/utils/test_mutation.py b/tests/utils/test_mutation.py index 2481185..5693f69 100644 --- a/tests/utils/test_mutation.py +++ b/tests/utils/test_mutation.py @@ -171,9 +171,8 @@ class Object: def test__get_function_args(): attrs = {"key": "value", "extra": "value"} - _get_function_args(int, attrs) == set() - _get_function_args(lambda key, missing: 1, attrs) == {"key"} - _get_function_args(lambda **kwargs: 1, attrs) == {"key", "extra"} - _get_function_args(Spec, attrs) == {"key"} - _get_function_args(OverflowSpec, attrs) == {"key", "extra"} - _get_function_args(sys.exit, attrs) == set() + assert _get_function_args(int, attrs) == set() + assert _get_function_args(lambda key, missing: 1, attrs) == {"key", "missing"} + assert _get_function_args(lambda **kwargs: 1, attrs) == {"key", "extra"} + assert _get_function_args(Spec, attrs) == {"key", "scalar", "list_values", "self"} + assert _get_function_args(OverflowSpec, attrs) == set() diff --git a/tests/utils/test_type_checking.py b/tests/utils/test_type_checking.py index 6454513..a398b80 100644 --- a/tests/utils/test_type_checking.py +++ b/tests/utils/test_type_checking.py @@ -1,5 +1,7 @@ from typing import Any, Callable, Dict, List, Set, TypeVar, Union +from typing_extensions import Literal + from spec_classes import spec_class from spec_classes.types import KeyedList, KeyedSet from spec_classes.utils.type_checking import ( @@ -9,7 +11,6 @@ type_instantiate, type_label, ) -from typing_extensions import Literal @spec_class