Skip to content

Commit acbe952

Browse files
committed
black reformatting
1 parent 6b5abe8 commit acbe952

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

inheritance_dict/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def concatMap(func, items):
2121
"""
2222
Yield items from the iterables produced by applying func to each element of items.
23-
23+
2424
func should be a callable that accepts a single item and returns an iterable; concatMap lazily iterates over items, calls func(item) for each, and yields each element from the resulting iterable in order.
2525
"""
2626
for item in items:
@@ -37,11 +37,11 @@ class BaseDict(dict):
3737
def _get_keys(self, key) -> Iterable[object]:
3838
"""
3939
Return an iterable of candidate lookup keys for dictionary lookup.
40-
40+
4141
This default implementation yields only the original `key`. Subclasses (e.g., those that perform
4242
Method Resolution Order or tuple-based fallback lookups) should override this to produce additional
4343
candidate keys to try in order.
44-
44+
4545
Returns:
4646
Iterable[object]: An iterable yielding candidate keys; by default a single-item tuple containing `key`.
4747
"""
@@ -50,7 +50,7 @@ def _get_keys(self, key) -> Iterable[object]:
5050
def __getitem__(self, key):
5151
"""
5252
Return the value mapped to `key` by trying candidate lookup keys produced by `_get_keys`.
53-
53+
5454
This performs lookups in the order produced by `self._get_keys(key)` and returns the first mapped value found. If no candidate is present in the mapping a `KeyError` is raised.
5555
"""
5656
for item in self._get_keys(key):
@@ -115,14 +115,14 @@ def _get_keys(self, key) -> Iterable[object]:
115115
"""
116116
Return an iterable of candidate lookup keys, expanding tuple keys by concatenating
117117
the candidate sequences for each element.
118-
118+
119119
If `key` is a tuple, yields all items produced by applying the superclass's
120120
`_get_keys` to each element of the tuple (flattened in element order). If `key`
121121
is not a tuple, delegates to the superclass's `_get_keys`.
122-
122+
123123
Parameters:
124124
key: The lookup key or a tuple of lookup keys.
125-
125+
126126
Returns:
127127
An iterable of candidate keys to try for dictionary lookup.
128128
"""
@@ -162,12 +162,12 @@ class TypeConvertingInheritanceDict(InheritanceDict):
162162
def _get_keys(self, key):
163163
"""
164164
Yield candidate lookup keys for a lookup key.
165-
165+
166166
Always yields the candidates produced by super()._get_keys(key). If key is not a type, also yields the candidates produced by super()._get_keys(type(key)) so lookups will fall back to the key's type (and its MRO) after the original candidates.
167-
167+
168168
Parameters:
169169
key: The lookup key. Non-type keys cause an additional sequence of candidate keys derived from type(key).
170-
170+
171171
Yields:
172172
Candidate keys (types or other lookup keys) in the order they should be tried.
173173
"""

typetest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import unittest
22
from datetime import date, datetime, time, timedelta
33

4-
from inheritance_dict import FallbackInheritanceDict, InheritanceDict, TypeConvertingInheritanceDict
4+
from inheritance_dict import (
5+
FallbackInheritanceDict,
6+
InheritanceDict,
7+
TypeConvertingInheritanceDict,
8+
)
59

610

711
class A(str):
@@ -13,14 +17,14 @@ class TypeTest(unittest.TestCase):
1317
def setUpClass(cls):
1418
"""
1519
Create shared class-level dictionary fixtures used by the tests.
16-
20+
1721
Sets up five fixtures on the test class:
1822
- inheritance_dict: InheritanceDict({object: 1, int: 2, str: 3, "a": 4})
1923
- inheritance_dict2: InheritanceDict({int: 2, str: 3, "a": 4})
2024
- inheritance_dict3: FallbackInheritanceDict({int: 2, str: 3, "a": 4})
2125
- type_converting_inheritance_dict: TypeConvertingInheritanceDict({object: 1, int: 2, str: 3, "a": 4})
2226
- type_converting_inheritance_dict2: TypeConvertingInheritanceDict({int: 2, str: 3, "a": 4})
23-
27+
2428
These fixtures are reused across tests to verify exact-type lookups, MRO-based resolution, tuple-key fallbacks, and type-converting behavior.
2529
"""
2630
super().setUpClass()

0 commit comments

Comments
 (0)