Skip to content

Commit

Permalink
fixing typing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tybruno committed Jun 20, 2024
1 parent d9c9548 commit a096e1c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions modifiable_items_dictionary/modifiable_items_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[1] Hettinger, R. (2023). (Advanced) Python For Engineers: Part 3.
"""
import contextlib
# pylint: disable=no-name-in-module
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -48,6 +49,7 @@
Union[Self, ValueCallable, Iterable[ValueCallable], None]
]


# Protocol
class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
"""Protocol for objects that support keys and getitem."""
Expand Down Expand Up @@ -327,13 +329,13 @@ def get(self, __key: Key, default=None):

@overload
def update(
self, other: SupportsKeysAndGetItem[Any, Value], /, **kwargs: Value
self, __m: SupportsKeysAndGetItem[Any, Value], **kwargs: Any
) -> None:
...

@overload
def update(
self, other: Iterable[Tuple[Any, Any]], /, **kwargs: Value
self, __m: Iterable[Tuple[Any, Any]], **kwargs: Any
) -> None:
...

Expand All @@ -343,14 +345,14 @@ def update(self, **kwargs: Value) -> None:

def update(
self,
other=None,
__m=None,
**kwargs,
):
# If there is a ValueError have the inherited class deal with it.
with contextlib.suppress(ValueError):
if other:
other = self._iterable_to_modified_dict(other)
if __m:
__m = self._iterable_to_modified_dict(__m)
if kwargs:
kwargs = self._iterable_to_modified_dict(kwargs)

dict.update(self, other or {}, **kwargs)
dict.update(self, __m or {}, **kwargs)

0 comments on commit a096e1c

Please sign in to comment.