Skip to content

Commit

Permalink
don't bother me, PyCharm
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Sulla committed May 5, 2024
1 parent 255deb5 commit 66259cd
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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)`

Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
bug_url = "https://github.com/Marco-Sulla/python-frozendict/issues"
author = "Marco Sulla"
author_email = "[email protected]"
license = "LGPL v3"
mylicense = "LGPL v3"
license_files = "LICENSE.txt"
description = "A simple immutable dictionary"

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -127,6 +125,7 @@
undef_macros = ["NDEBUG"]


# noinspection PyShadowingNames
def get_ext_module(
fullname,
sources,
Expand All @@ -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,
Expand All @@ -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,

Expand Down
3 changes: 3 additions & 0 deletions src/frozendict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
try:
from ._frozendict import *
c_ext = True
# noinspection PyUnresolvedReferences
del _frozendict
except ImportError:
from ._frozendict_py import *
Expand Down Expand Up @@ -37,6 +38,8 @@ def default(self, obj):


from collections.abc import Mapping

# noinspection PyUnresolvedReferences
Mapping.register(frozendict)
del Mapping

Expand Down
1 change: 1 addition & 0 deletions src/frozendict/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
11 changes: 8 additions & 3 deletions src/frozendict/_frozendict_py.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -14,6 +14,7 @@ def immutable(self, *args, **kwargs):
_empty_frozendict = None


# noinspection PyPep8Naming
class frozendict(dict):
r"""
A simple immutable dictionary.
Expand All @@ -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:
Expand Down Expand Up @@ -72,6 +75,7 @@ def __new__(e4b37cdf_d78a_4632_bade_6f0579d8efac, *args, **kwargs):

return self

# noinspection PyMissingConstructor
def __init__(self, *args, **kwargs):
pass

Expand Down Expand Up @@ -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)
Expand All @@ -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))


Expand Down
1 change: 1 addition & 0 deletions src/frozendict/cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# fix for python 3.9-

if not issubclass(array, MutableSequence):
# noinspection PyUnresolvedReferences
MutableSequence.register(array)


Expand Down
1 change: 1 addition & 0 deletions src/frozendict/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# created on a python-only implementation that
# specifically mention frozendict.core.frozendict

# noinspection PyUnresolvedReferences
from frozendict import frozendict
6 changes: 6 additions & 0 deletions src/frozendict/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def patchOrUnpatchJson(*, patch, warn = True):

OldJsonEncoder = self._OldJsonEncoder

# noinspection PyUnresolvedReferences, PyProtectedMember
FrozendictJsonEncoder = cool._getFrozendictJsonEncoder(
OldJsonEncoder
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -139,6 +141,7 @@ def patchOrUnpatchMutableMappingSubclasshook(*, patch, warn = True):
oldMutableMappingSubclasshook = self._oldMutableMappingSubclasshook

if patch:
# noinspection PyDecorator
@classmethod
def frozendictMutableMappingSubclasshook(
klass,
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __len__(self):
return len(self._dict)


# noinspection PyMethodMayBeStatic
class FrozendictCommonTest(FrozendictTestBase):
@property
def is_mapping_implemented(self):
Expand Down Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 66259cd

Please sign in to comment.