diff --git a/src/attrbox/attrdict.py b/src/attrbox/attrdict.py index 01fbf64..5700211 100644 --- a/src/attrbox/attrdict.py +++ b/src/attrbox/attrdict.py @@ -51,16 +51,16 @@ def copy(self: Self) -> Self: """ return self.__class__(super().copy()) - def __contains__(self, name: Any) -> bool: - """Return `True` if `name` is a key. + def __contains__(self, key: Any) -> bool: + """Return `True` if `key` is a key. Args: - name (Any): typically a `AnyIndex`. If it's a string, + key (Any): typically a `AnyIndex`. If it's a string, the check proceeds as usual. If it's a `Sequence`, the checks are performed using `.get()`. Returns: - bool: `True` if the `name` is a valid key, `False` otherwise. + bool: `True` if the `key` is a valid key, `False` otherwise. Examples: Normal checking works as expected: @@ -77,7 +77,7 @@ def __contains__(self, name: Any) -> bool: >>> ['a', 1, 'x'] in items False """ - return self.get(name, NOT_FOUND) is not NOT_FOUND + return self.get(key, NOT_FOUND) is not NOT_FOUND def __getattr__(self, name: str) -> Optional[Any]: """Return the value of the attribute or `None`. @@ -177,11 +177,11 @@ def __delattr__(self, name: str) -> None: except AttributeError: # use key/value del self[name] - def __getitem__(self, name: AnyIndex) -> Optional[Any]: + def __getitem__(self, key: AnyIndex) -> Optional[Any]: """Return the value of the key. Args: - name (AnyIndex): key name or Sequence of the path to a key + key (AnyIndex): key name or Sequence of the path to a key Returns: Any: value of the key or `None` if it cannot be found @@ -193,13 +193,13 @@ def __getitem__(self, name: AnyIndex) -> Optional[Any]: >>> item['b'] is None True """ - return self.get(name) + return self.get(key) - def __setitem__(self, name: AnyIndex, value: Any) -> None: + def __setitem__(self, key: AnyIndex, value: Any) -> None: """Set the value of a key. Args: - name (BoxIndex): key name + key (AnyIndex): key name value (Any): key value Examples: @@ -212,13 +212,13 @@ def __setitem__(self, name: AnyIndex, value: Any) -> None: >>> item.a.b 10 """ - self.set(name, value) + self.set(key, value) - def __delitem__(self, name: str) -> None: + def __delitem__(self, key: str) -> None: """Delete a key. Args: - name (str): key name + key (str): key name Examples: >>> item = AttrDict(a=1) @@ -233,7 +233,7 @@ def __delitem__(self, name: str) -> None: {'a': 1} """ try: - super().__delitem__(name) + super().__delitem__(key) except KeyError: pass diff --git a/src/attrbox/config.py b/src/attrbox/config.py index cb998c5..73e1421 100644 --- a/src/attrbox/config.py +++ b/src/attrbox/config.py @@ -7,6 +7,7 @@ from typing import Callable from typing import Dict from typing import List +from typing import LiteralString from typing import Mapping from typing import Optional from typing import Sequence @@ -22,7 +23,7 @@ from . import env PYTHON_KEYWORDS: List[ - str + LiteralString ] = """\ False await else import pass None break except in raise diff --git a/src/attrbox/env.py b/src/attrbox/env.py index 7e5da49..c07daa7 100644 --- a/src/attrbox/env.py +++ b/src/attrbox/env.py @@ -56,6 +56,7 @@ class SupportsRead(Protocol): # pylint: disable=too-few-public-methods def read(self) -> str: """Read the contents of the file-like object.""" + return "" # pragma: no cover def expand( @@ -118,7 +119,7 @@ def _repl(match: Match[str]) -> str: name = name.split(".") if name in values: - value = str(values[name]) + value = str(values[name]) # pyright: ignore return value return _RE_EXPAND.sub(_repl, value) diff --git a/src/attrbox/fn.py b/src/attrbox/fn.py index 053bfa3..9d50808 100644 --- a/src/attrbox/fn.py +++ b/src/attrbox/fn.py @@ -35,6 +35,7 @@ class SupportsItem(Protocol): # pragma: no cover def __contains__(self, key: Any) -> bool: """Return `True` if `key` exists, `False` otherwise.""" + return False def __getitem__(self, key: Any) -> Any: """Return value of `key`."""