Skip to content

Commit

Permalink
Merge pull request #1 from LarsHill/fix-metadict-unpacking-warning
Browse files Browse the repository at this point in the history
Fix metadict unpacking warning
  • Loading branch information
LarsHill authored Feb 14, 2022
2 parents d87c567 + d803560 commit 97be72e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metadict/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

_this_year = time.strftime("%Y")
__version__ = '0.1.0'
__version__ = '0.1.1'
__author__ = 'Lars Hillebrand'
__author_email__ = 'hokage555@web.de'
__license__ = 'Apache-2.0'
Expand Down
15 changes: 15 additions & 0 deletions metadict/metadict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import keyword
import re
import warnings
from collections.abc import KeysView
from typing import MutableMapping, Dict, Iterator, TypeVar, Iterable, Optional, Mapping, Any, Tuple


Expand Down Expand Up @@ -265,3 +266,17 @@ def _contains_mapping(iterable: Iterable, ignore: Optional[type] = None) -> bool
elif isinstance(x, (list, set, tuple)):
return MetaDict._contains_mapping(x, ignore)
return False

# add the following inherited methods from collections.abc.Mapping directly to make pycharm happy
# (removing an annoying warning for dict unpacking)
def __contains__(self, key):
try:
self[key]
except KeyError:
return False
else:
return True

def keys(self):
"""D.keys() -> a set-like object providing a view on D's keys"""
return KeysView(self)
5 changes: 5 additions & 0 deletions tests/test_metadict.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def test_update(config: Dict):
assert cfg == config


def test_contains(config: Dict):
cfg = MetaDict(config)
assert 'model' in cfg


def test_copy(config: Dict):
cfg = MetaDict(config)
assert copy.copy(cfg) is not cfg
Expand Down

0 comments on commit 97be72e

Please sign in to comment.