Skip to content

Commit

Permalink
Merge 3e3f08e into 8701d4a
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-maier committed Apr 12, 2021
2 parents 8701d4a + 3e3f08e commit 1499c88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Released: not yet

* Docs: Fixed development status of Pypi package to be Beta.

* Fixed that there is no '__reversed__()' method on dict before Python 3.8.

**Enhancements:**

* Removed dependency to 'six' package.
Expand Down
8 changes: 8 additions & 0 deletions immutable_views/_dict_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
# Indicates Python dict supports the has_key() method
_DICT_SUPPORTS_HAS_KEY = sys.version_info[0:2] == (2, 7)

# Indicates Python dict supports the __reversed__() method
_DICT_SUPPORTS_REVERSED = sys.version_info[0:2] >= (3, 8)

# Indicates Python dict supports the __or__/__ror__() methods
_DICT_SUPPORTS_OR = sys.version_info[0:2] >= (3, 9)

Expand Down Expand Up @@ -135,6 +138,8 @@ def __reversed__(self):
``reversed(self) ...``:
Return an iterator through the dictionary in reversed iteration order.
Added in Python 3.8
The returned iterator yields the items in the underlying dictionary in
the reversed iteration order.
"""
Expand Down Expand Up @@ -506,6 +511,9 @@ def __ror__(self, other):
if not _DICT_SUPPORTS_HAS_KEY and not _BUILDING_DOCS:
del DictView.has_key

if not _DICT_SUPPORTS_REVERSED and not _BUILDING_DOCS:
del DictView.__reversed__

if not _DICT_SUPPORTS_OR and not _BUILDING_DOCS:
del DictView.__or__
del DictView.__ror__
15 changes: 9 additions & 6 deletions tests/unittest/test_dict_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def __ror__(self, other):
# Indicates Python dict supports the has_key() method
DICT_SUPPORTS_HAS_KEY = sys.version_info[0:2] == (2, 7)

# Indicates Python dict supports the __reversed__() method
DICT_SUPPORTS_REVERSED = sys.version_info[0:2] >= (3, 8)

# Indicates Python dict supports the __or__/__ror__() methods
DICT_SUPPORTS_OR = sys.version_info[0:2] >= (3, 9)

Expand Down Expand Up @@ -790,26 +793,26 @@ def test_DictView_has_key(testcase, obj, key, exp_result):
(
"Empty dict",
dict(
obj=DictView(OrderedDict()),
obj=DictView({}),
exp_keys=[],
),
None, None, True
None if DICT_SUPPORTS_REVERSED else TypeError, None, DICT_IS_ORDERED
),
(
"Dict with one item",
dict(
obj=DictView(OrderedDict([('Dog', 'Cat')])),
obj=DictView({'Dog': 'Cat'}),
exp_keys=['Dog'],
),
None, None, True
None if DICT_SUPPORTS_REVERSED else TypeError, None, DICT_IS_ORDERED
),
(
"Dict with two items",
dict(
obj=DictView(OrderedDict([('Dog', 'Cat'), ('Budgie', 'Fish')])),
obj=DictView({'Dog': 'Cat', 'Budgie': 'Fish'}),
exp_keys=['Budgie', 'Dog'],
),
None, None, True
None if DICT_SUPPORTS_REVERSED else TypeError, None, DICT_IS_ORDERED
),
]

Expand Down

0 comments on commit 1499c88

Please sign in to comment.