mypy: Fix disallow_untyped_calls check fallout
Add return type annotations and parameter type hints to previously untyped functions, preparing for disallow_untyped_calls enforcement: - ArgsContainer.py: keys() -> Iterable[str] - Object.py: Object.__init__() -> None - ShuntingYard.py: tokenize(), infix_to_postfix(), __init__(), add_operator(), Stack methods, debug(), Calculator/Matcher.__init__() - ShellCmd.py: __exec(), __cleanup(), init(), cleanup(), __init__() - Auth.py: __bind() -> Connection, import Connection - TableIoHandler.py: _check_non_nullable() -> None, buf annotation - Queries.py: _add() -> None - rows.py: __equal(), rows_duplicates(), rows_check_not_null(), rows_dump(), rows_dumps() with proper type signatures - CompositeForeignKey.py: __table() -> Table - EventRouter.py: iter_peers() -> Iterator[tuple[str, Any]] - MapAttr2Shape.py: __value(), __add_key_nodegraphics() - ldap.py: __search() -> str, collect() -> set[str] - multi_key_dict.py: has_key(), get_other_keys(), iterkeys(), get_values_from_str(), test_multi_key_dict(), __init__(), items_dict annotation Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
ec342ba172
commit
e014a9251f
1 changed files with 76 additions and 66 deletions
|
|
@ -79,10 +79,10 @@ class multi_key_dict(object):
|
|||
print k[1000] # will print 'kilo' as value was updated
|
||||
"""
|
||||
|
||||
def __init__(self, mapping_or_iterable = None, **kwargs):
|
||||
def __init__(self, mapping_or_iterable: Any = None, **kwargs: Any) -> None:
|
||||
""" Initializes dictionary from an optional positional argument and a possibly
|
||||
empty set of keyword arguments."""
|
||||
self.items_dict = {}
|
||||
self.items_dict: dict[str, Any] = {}
|
||||
if mapping_or_iterable is not None:
|
||||
if type(mapping_or_iterable) is dict:
|
||||
mapping_or_iterable = mapping_or_iterable.items()
|
||||
|
|
@ -181,11 +181,11 @@ class multi_key_dict(object):
|
|||
|
||||
return False
|
||||
|
||||
def has_key(self, key):
|
||||
def has_key(self, key: Any) -> bool:
|
||||
""" Returns True if this object contains an item referenced by the key."""
|
||||
return key in self
|
||||
|
||||
def get_other_keys(self, key, including_current = False):
|
||||
def get_other_keys(self, key: Any, including_current: bool = False) -> list[Any]:
|
||||
""" Returns list of other keys that are mapped to the same value as specified
|
||||
key. @param key - key for which other keys should be returned. @param
|
||||
including_current if set to True - key will also appear on this list."""
|
||||
|
|
@ -196,7 +196,7 @@ class multi_key_dict(object):
|
|||
other_keys.remove(key)
|
||||
return other_keys
|
||||
|
||||
def iteritems(self, key_type = None, return_all_keys = False):
|
||||
def iteritems(self, key_type: Any = None, return_all_keys: bool = False) -> Any:
|
||||
""" Returns an iterator over the dictionary's (key, value) pairs.
|
||||
|
||||
@param key_type if specified, iterator will be returning only (key,value)
|
||||
|
|
@ -224,7 +224,7 @@ class multi_key_dict(object):
|
|||
keys = tuple(k for k in keys if isinstance(k, key_type))
|
||||
yield keys, value
|
||||
|
||||
def iterkeys(self, key_type = None, return_all_keys = False):
|
||||
def iterkeys(self, key_type: Any = None, return_all_keys: bool = False) -> Any:
|
||||
""" Returns an iterator over the dictionary's keys.
|
||||
@param key_type if specified, iterator for a dictionary of this type will
|
||||
be used.
|
||||
|
|
@ -353,7 +353,7 @@ class multi_key_dict(object):
|
|||
dict_str = '{%s}' % (', '.join(items))
|
||||
return dict_str
|
||||
|
||||
def test_multi_key_dict():
|
||||
def test_multi_key_dict() -> None:
|
||||
|
||||
def contains_all(cont, in_items):
|
||||
return False not in [c in cont for c in in_items]
|
||||
|
|
@ -429,8 +429,8 @@ def test_multi_key_dict():
|
|||
), ('str(m) should end with \'}\', but does with \'%c\'' % m_str[-1])
|
||||
|
||||
# check if all key-values are there as expected. They might be sorted differently
|
||||
def get_values_from_str(dict_str):
|
||||
sorted_keys_and_values = []
|
||||
def get_values_from_str(dict_str: str) -> list[tuple[tuple[str, ...], str]]:
|
||||
sorted_keys_and_values: list[tuple[tuple[str, ...], str]] = []
|
||||
for k in dict_str.split(', ('):
|
||||
keys, val = k.strip('{}() ').replace(')', '').split(':')
|
||||
keys = tuple(sorted([k.strip() for k in keys.split(',')]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue