diff --git a/README.md b/README.md index 1591fc0..e4258d7 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ objects. Reinvoking `__init__` does not alter the object. The API is the same as `dict`, without methods that can change the immutability. So it supports also `fromkeys`, unlike other implementations. -Furthermore it can be `pickle`d, un`pickle`d and have an hash, if all values +Furthermore, it can be `pickle`d, un`pickle`d and have a hash, if all values are hashable. You can also add any `dict` to a `frozendict` using the `|` operator. The result is a new `frozendict`. @@ -56,7 +56,7 @@ The API is the same of `dict` of Python 3.10, without the methods and operands w ### `__hash__()` -If all the values of the `frozendict` are hashable, returns an hash, otherwise raises a TypeError. +If all the values of the `frozendict` are hashable, returns a hash, otherwise raises a TypeError. ### `set(key, value)` diff --git a/setup.py b/setup.py index 0387ccb..cb06a26 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ bug_url = "https://github.com/Marco-Sulla/python-frozendict/issues" author = "Marco Sulla" author_email = "marcosullaroma@gmail.com" -license = "LGPL v3" +mylicense = "LGPL v3" license_files = "LICENSE.txt" description = "A simple immutable dictionary" @@ -46,8 +46,6 @@ readme_path = curr_dir / readme_filename readme_content_type = "text/markdown" -long_description = "" - with open(readme_path) as f: long_description = f.read() @@ -127,6 +125,7 @@ undef_macros = ["NDEBUG"] +# noinspection PyShadowingNames def get_ext_module( fullname, sources, @@ -147,6 +146,7 @@ def get_ext_module( return ext_module +# noinspection PyShadowingNames def get_ext_module_1(optional): return get_ext_module( fullname = ext1_fullname, @@ -160,13 +160,14 @@ def get_ext_module_1(optional): # C extension - END +# noinspection PyUnresolvedReferences common_setup_args = dict( name = name, author = author, author_email = author_email, version = version, python_requires = python_requires, - license = license, + license = mylicense, license_files = (license_files, ), url = main_url, diff --git a/src/frozendict/__init__.py b/src/frozendict/__init__.py index b59c804..c1fbf95 100644 --- a/src/frozendict/__init__.py +++ b/src/frozendict/__init__.py @@ -5,6 +5,7 @@ try: from ._frozendict import * c_ext = True + # noinspection PyUnresolvedReferences del _frozendict except ImportError: from ._frozendict_py import * @@ -37,6 +38,8 @@ def default(self, obj): from collections.abc import Mapping + +# noinspection PyUnresolvedReferences Mapping.register(frozendict) del Mapping diff --git a/src/frozendict/__init__.pyi b/src/frozendict/__init__.pyi index b028f25..9e57f63 100644 --- a/src/frozendict/__init__.pyi +++ b/src/frozendict/__init__.pyi @@ -15,6 +15,7 @@ K2 = TypeVar("K2") V2 = TypeVar("V2", covariant=True) SelfT = TypeVar("SelfT", bound=frozendict[K, V]) +# noinspection PyPep8Naming class frozendict(Mapping[K, V]): @overload def __new__(cls: Type[SelfT]) -> SelfT: ... diff --git a/src/frozendict/_frozendict_py.py b/src/frozendict/_frozendict_py.py index 1b4c545..ade957a 100644 --- a/src/frozendict/_frozendict_py.py +++ b/src/frozendict/_frozendict_py.py @@ -1,7 +1,7 @@ from copy import deepcopy -def immutable(self, *args, **kwargs): +def immutable(self, *_args, **_kwargs): r""" Function for not implemented method since the object is immutable """ @@ -14,6 +14,7 @@ def immutable(self, *args, **kwargs): _empty_frozendict = None +# noinspection PyPep8Naming class frozendict(dict): r""" A simple immutable dictionary. @@ -34,11 +35,13 @@ def fromkeys(cls, *args, **kwargs): return cls(dict.fromkeys(*args, **kwargs)) + # noinspection PyMethodParameters def __new__(e4b37cdf_d78a_4632_bade_6f0579d8efac, *args, **kwargs): cls = e4b37cdf_d78a_4632_bade_6f0579d8efac has_kwargs = bool(kwargs) continue_creation = True + self = None # check if there's only an argument and it's of the same class if len(args) == 1 and not has_kwargs: @@ -72,6 +75,7 @@ def __new__(e4b37cdf_d78a_4632_bade_6f0579d8efac, *args, **kwargs): return self + # noinspection PyMissingConstructor def __init__(self, *args, **kwargs): pass @@ -217,7 +221,7 @@ def __delitem__(self, key, *args, **kwargs): ) -def frozendict_or(self, other, *args, **kwargs): +def frozendict_or(self, other, *_args, **_kwargs): res = {} res.update(self) res.update(other) @@ -229,9 +233,10 @@ def frozendict_or(self, other, *args, **kwargs): frozendict.__ior__ = frozendict_or try: + # noinspection PyStatementEffect frozendict.__reversed__ except AttributeError: - def frozendict_reversed(self, *args, **kwargs): + def frozendict_reversed(self, *_args, **_kwargs): return reversed(tuple(self)) diff --git a/src/frozendict/cool.py b/src/frozendict/cool.py index c8decb4..df84d50 100644 --- a/src/frozendict/cool.py +++ b/src/frozendict/cool.py @@ -7,6 +7,7 @@ # fix for python 3.9- if not issubclass(array, MutableSequence): + # noinspection PyUnresolvedReferences MutableSequence.register(array) diff --git a/src/frozendict/core.py b/src/frozendict/core.py index b20e87b..298d8fa 100644 --- a/src/frozendict/core.py +++ b/src/frozendict/core.py @@ -2,4 +2,5 @@ # created on a python-only implementation that # specifically mention frozendict.core.frozendict +# noinspection PyUnresolvedReferences from frozendict import frozendict diff --git a/src/frozendict/monkeypatch.py b/src/frozendict/monkeypatch.py index f0e13ff..9f5b7b1 100644 --- a/src/frozendict/monkeypatch.py +++ b/src/frozendict/monkeypatch.py @@ -36,6 +36,7 @@ def patchOrUnpatchJson(*, patch, warn = True): OldJsonEncoder = self._OldJsonEncoder + # noinspection PyUnresolvedReferences, PyProtectedMember FrozendictJsonEncoder = cool._getFrozendictJsonEncoder( OldJsonEncoder ) @@ -83,6 +84,7 @@ def patchOrUnpatchOrjson(*, patch, warn = True): from importlib import import_module self = import_module(__name__) + # noinspection PyUnresolvedReferences import orjson if self._oldOrjsonDumps is None: @@ -139,6 +141,7 @@ def patchOrUnpatchMutableMappingSubclasshook(*, patch, warn = True): oldMutableMappingSubclasshook = self._oldMutableMappingSubclasshook if patch: + # noinspection PyDecorator @classmethod def frozendictMutableMappingSubclasshook( klass, @@ -168,9 +171,12 @@ def frozendictMutableMappingSubclasshook( MutableMapping.__subclasshook__ = defaultMutableMappingSubclasshook try: + # noinspection PyUnresolvedReferences, PyProtectedMember MutableMapping._abc_caches_clear() except AttributeError: + # noinspection PyUnresolvedReferences, PyProtectedMember MutableMapping._abc_cache.discard(frozendict) + # noinspection PyUnresolvedReferences, PyProtectedMember MutableMapping._abc_negative_cache.discard(frozendict) diff --git a/test/common.py b/test/common.py index 4484799..9fbacb3 100644 --- a/test/common.py +++ b/test/common.py @@ -31,6 +31,7 @@ def __len__(self): return len(self._dict) +# noinspection PyMethodMayBeStatic class FrozendictCommonTest(FrozendictTestBase): @property def is_mapping_implemented(self): @@ -75,6 +76,7 @@ def test_normalget(self, fd): def test_keyerror(self, fd): with pytest.raises(KeyError): + # noinspection PyStatementEffect fd["Brignano"] def test_len(self, fd, fd_dict): diff --git a/test/debug.py b/test/debug.py index 7af7f40..a686379 100755 --- a/test/debug.py +++ b/test/debug.py @@ -239,6 +239,7 @@ def func_14(): @trace() def func_15(): + # noinspection PyStatementEffect fd_1 == dict_1 @@ -247,6 +248,7 @@ def func_15(): @trace() def func_16(): + # noinspection PyStatementEffect fd_1 == fd_1 @@ -255,6 +257,7 @@ def func_16(): @trace() def func_17(): + # noinspection PyStatementEffect fd_1 != dict_hole @@ -263,6 +266,7 @@ def func_17(): @trace() def func_18(): + # noinspection PyStatementEffect fd_1 != dict_2 @@ -271,6 +275,7 @@ def func_18(): @trace() def func_19(): + # noinspection PyStatementEffect fd_1 == dict_hole @@ -279,6 +284,7 @@ def func_19(): @trace() def func_20(): + # noinspection PyStatementEffect fd_1 == dict_2 @@ -399,6 +405,7 @@ def func_34(): @trace() def func_35(): + # noinspection PyStatementEffect frozendict_class() == frozendict_class() @@ -479,6 +486,7 @@ def func_44(): @trace() def func_45(): + # noinspection PyStatementEffect,PyUnresolvedReferences fd_1.keys().mapping == fd_1 @@ -487,6 +495,7 @@ def func_45(): @trace() def func_46(): + # noinspection PyStatementEffect, PyUnresolvedReferences fd_1.items().mapping == fd_1 @@ -495,6 +504,7 @@ def func_46(): @trace() def func_47(): + # noinspection PyStatementEffect, PyUnresolvedReferences fd_1.values().mapping == fd_1 @@ -503,6 +513,7 @@ def func_47(): @trace() def func_48(): + # noinspection PyStatementEffect fd_1[key_in] @@ -535,6 +546,7 @@ def func_51(): @trace() def func_52(): + # noinspection PyStatementEffect key_in in fd_1 @@ -543,6 +555,7 @@ def func_52(): @trace() def func_53(): + # noinspection PyStatementEffect key_notin in fd_1 @@ -583,6 +596,7 @@ def func_57(): @trace() def func_58(): + # noinspection PyStatementEffect fd_1.keys() == dict_1.keys() @@ -591,6 +605,7 @@ def func_58(): @trace() def func_59(): + # noinspection PyStatementEffect fd_1.items() == dict_1.items() @@ -599,6 +614,7 @@ def func_59(): @trace() def func_60(): + # noinspection PyStatementEffect key_notin in fd_1.keys() @@ -607,6 +623,7 @@ def func_60(): @trace() def func_61(): + # noinspection PyStatementEffect (key_notin, 0) in fd_1.items() @@ -615,6 +632,7 @@ def func_61(): @trace() def func_62(): + # noinspection PyStatementEffect FMissing(fd_1)[0] @@ -624,6 +642,7 @@ def func_62(): @trace() def func_63(): mp = Map(dict_1) + # noinspection PyStatementEffect frozendict_class(mp) == dict_1 @@ -752,6 +771,7 @@ def func_78(): @trace() def func_79(): + # noinspection PyStatementEffect frozendict_class(dict_hole).keys() < fd_1.keys() @@ -760,6 +780,7 @@ def func_79(): @trace() def func_80(): + # noinspection PyStatementEffect frozendict_class(dict_hole).keys() <= fd_1.keys() @@ -768,6 +789,7 @@ def func_80(): @trace() def func_81(): + # noinspection PyStatementEffect frozendict_class(dict_hole).items() < fd_1.items() @@ -776,6 +798,7 @@ def func_81(): @trace() def func_82(): + # noinspection PyStatementEffect fd_1.keys() > frozendict_class(dict_hole).keys() @@ -784,6 +807,7 @@ def func_82(): @trace() def func_83(): + # noinspection PyStatementEffect fd_1.keys() >= frozendict_class(dict_hole).keys() @@ -792,6 +816,7 @@ def func_83(): @trace() def func_84(): + # noinspection PyStatementEffect fd_1.items() > frozendict_class(dict_hole).items() @@ -800,6 +825,7 @@ def func_84(): @trace() def func_85(): + # noinspection PyStatementEffect fd_1.items() >= frozendict_class(dict_hole).items() diff --git a/test/frozendict_only.py b/test/frozendict_only.py index 1fd3a0b..77a7269 100644 --- a/test/frozendict_only.py +++ b/test/frozendict_only.py @@ -5,6 +5,7 @@ from .base import FrozendictTestBase +# noinspection PyMethodMayBeStatic class FrozendictOnlyTest(FrozendictTestBase): def test_empty(self, fd_empty): fd_empty_set = self.FrozendictClass({}) @@ -26,6 +27,7 @@ def test_setattr(self, fd): fd._initialized = False def test_copy(self, fd): + # noinspection PyTestUnpassedFixture assert fd.copy() is fd def test_copycopy(self, fd, fd_unhashable): @@ -36,6 +38,7 @@ def test_deepcopy(self, fd): assert deepcopy(fd) is fd def test_init(self, fd): + # noinspection PyTestUnpassedFixture fd_copy = fd.copy() fd_clone = self.FrozendictClass(dict(fd)) fd.__init__({"Trump": "Donald"}) diff --git a/test/subclass_only.py b/test/subclass_only.py index 2b82a43..d0006f8 100644 --- a/test/subclass_only.py +++ b/test/subclass_only.py @@ -2,6 +2,7 @@ from .base import FrozendictTestBase +# noinspection PyMethodMayBeStatic class FrozendictSubclassOnlyTest(FrozendictTestBase): _FrozendictMissingClass = None @@ -36,6 +37,7 @@ def test_constructor_self_sub(self, fd): assert fd is not fd_clone def test_copy_sub(self, fd): + # noinspection PyTestUnpassedFixture fd_copy = fd.copy() assert fd_copy == fd assert fd_copy is not fd @@ -54,6 +56,7 @@ def test_deepcopy_sub(self, fd): assert fd_copy is not fd def test_init_sub(self, fd): + # noinspection PyTestUnpassedFixture fd_copy = fd.copy() fd_clone = self.FrozendictClass(dict(fd)) fd.__init__({"Trump": "Donald"}) diff --git a/test/test_freeze.py b/test/test_freeze.py index bb782db..f0cc432 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -99,11 +99,14 @@ def after_cure(): def after_cure_a(a): return custom_a_converter(a) + @pytest.fixture def my_enum(): Color = Enum('Color', ['RED', 'GREEN', 'BLUE']) + # noinspection PyUnresolvedReferences return Color.RED + def test_deepfreeze(before_cure, after_cure): assert cool.deepfreeze(before_cure) == after_cure @@ -195,7 +198,7 @@ def test_original_immutate(): "nested": {"int": 1}, } - frozen = cool.deepfreeze(unfrozen) + cool.deepfreeze(unfrozen) assert type(unfrozen["nested"]) is dict