Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings #45

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions immutabledict/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import sys
from collections import OrderedDict
from collections.abc import Mapping
from typing import Dict, TypeVar

if sys.version_info >= (3, 7):
from typing import Mapping
else: # pragma: no cover
from collections.abc import Mapping as _BaseMapping

class _MappingMeta(type):
def __getitem__(self, *args):
return _BaseMapping

class Mapping(metaclass=_MappingMeta):
pass


__version__ = "1.2.0"

_K = TypeVar("_K")
_V = TypeVar("_V")


class immutabledict(Mapping):
class immutabledict(Mapping[_K, _V]):
"""
An immutable wrapper around dictionaries that implements the complete :py:class:`collections.Mapping`
interface. It can be used as a drop-in replacement for dictionaries where immutability is desired.
Expand All @@ -26,7 +43,7 @@ def __getitem__(self, key):
def __contains__(self, key):
return key in self._dict

def copy(self, **add_or_replace):
def copy(self, **add_or_replace: Dict[_K, _V]) -> "immutabledict[_K, _V]":
return self.__class__(self, **add_or_replace)

def __iter__(self):
Expand Down
Empty file added immutabledict/py.typed
Empty file.
148 changes: 147 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ black = {version = "^20.8b1", python = "^3.6"}
pytest = "^6.2"
isort = {version = "^5.8", python = "^3.6"}
pytest-cov = "^2.11"
mypy = "^0.812"
tox = "^3.23.0"

[build-system]
requires = ["poetry>=0.12"]
requires = ["poetry>=1.1.5"]
build-backend = "poetry.masonry.api"
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tox]
isolated_build = true
envlist = py36,py37,py38,py39

[testenv]
whitelist_externals = poetry
commands =
poetry install -v
poetry run pytest tests/