Skip to content

Commit

Permalink
delint
Browse files Browse the repository at this point in the history
  • Loading branch information
metaist committed Dec 31, 2023
1 parent 4940bf5 commit ba8284e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/attrbox/attrdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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`.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -233,7 +233,7 @@ def __delitem__(self, name: str) -> None:
{'a': 1}
"""
try:
super().__delitem__(name)
super().__delitem__(key)
except KeyError:
pass

Expand Down
3 changes: 2 additions & 1 deletion src/attrbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +23,7 @@
from . import env

PYTHON_KEYWORDS: List[
str
LiteralString
] = """\
False await else import pass
None break except in raise
Expand Down
3 changes: 2 additions & 1 deletion src/attrbox/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/attrbox/fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down

0 comments on commit ba8284e

Please sign in to comment.