Skip to content

Commit

Permalink
Merge pull request #45 from aecay/typings
Browse files Browse the repository at this point in the history
Add typings
  • Loading branch information
corenting authored Apr 9, 2021
2 parents 7245a22 + c97c464 commit 365658e
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 5 deletions.
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/

0 comments on commit 365658e

Please sign in to comment.