Skip to content

Commit 7307876

Browse files
committed
Update type hints
1 parent 3a2a9af commit 7307876

24 files changed

+129
-127
lines changed

domdf_python_tools/bases.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def __rmod__(self: _F, other: float) -> _F:
456456
return self.__class__(float(self).__rmod__(other))
457457

458458
def __rdivmod__(self: _F, other: float) -> Tuple[_F, _F]:
459-
return tuple(self.__class__(x) for x in float(self).__rdivmod__(other)) # type: ignore
459+
return tuple(self.__class__(x) for x in float(self).__rdivmod__(other)) # type: ignore[return-value]
460460

461461
def __rpow__(self: _F, other: float, mod=None) -> _F:
462462
return self.__class__(float(self).__rpow__(other, mod))
@@ -471,7 +471,13 @@ def __trunc__(self) -> int:
471471

472472
return float(self).__trunc__()
473473

474-
def __round__(self, ndigits: Optional[int] = None) -> Union[int, float]: # type: ignore
474+
@overload
475+
def __round__(self, ndigits: None = ...) -> int: ...
476+
477+
@overload
478+
def __round__(self, ndigits: int) -> float: ...
479+
480+
def __round__(self, ndigits: Optional[int] = None) -> Union[int, float]:
475481
"""
476482
Round the :class:`~.UserFloat` to ``ndigits`` decimal places, defaulting to ``0``.
477483
@@ -622,7 +628,7 @@ def replace(self: _LU, what: _T, with_: _T) -> _LU:
622628

623629
return self
624630

625-
def sort( # type: ignore
631+
def sort( # type: ignore[override]
626632
self: _LU,
627633
*,
628634
key=None,
@@ -643,39 +649,39 @@ def sort( # type: ignore
643649
super().sort(key=key, reverse=reverse)
644650
return self
645651

646-
def reverse(self: _LU) -> _LU: # type: ignore # noqa: D102
652+
def reverse(self: _LU) -> _LU: # type: ignore[override] # noqa: D102
647653
super().reverse()
648654
return self
649655

650-
def append( # type: ignore # noqa: D102
656+
def append( # type: ignore[override] # noqa: D102
651657
self: _LU,
652658
item: _T,
653659
) -> _LU:
654660
super().append(item)
655661
return self
656662

657-
def extend( # type: ignore # noqa: D102
663+
def extend( # type: ignore[override] # noqa: D102
658664
self: _LU,
659665
other: Iterable[_T],
660666
) -> _LU:
661667
super().extend(other)
662668
return self
663669

664-
def insert( # type: ignore # noqa: D102
670+
def insert( # type: ignore[override] # noqa: D102
665671
self: _LU,
666672
i: int,
667673
item: _T,
668674
) -> _LU:
669675
super().insert(i, item)
670676
return self
671677

672-
def remove( # type: ignore # noqa: D102
678+
def remove( # type: ignore[override] # noqa: D102
673679
self: _LU,
674680
item: _T,
675681
) -> _LU:
676682
super().remove(item)
677683
return self
678684

679-
def clear(self: _LU) -> _LU: # type: ignore # noqa: D102
685+
def clear(self: _LU) -> _LU: # type: ignore[override] # noqa: D102
680686
super().clear()
681687
return self

domdf_python_tools/dates.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def utc_timestamp_to_datetime(
147147
if sys.version_info <= (3, 7, 2): # pragma: no cover (py37+)
148148
MonthsType = OrderedDict
149149
else: # pragma: no cover (<py37)
150-
MonthsType = typing.OrderedDict[str, str] # type: ignore # noqa: TYP006
150+
MonthsType = typing.OrderedDict[str, str] # type: ignore[misc,assignment] # noqa: TYP006
151151

152152
#: Mapping of 3-character shortcodes to full month names.
153153
months: MonthsType = OrderedDict(
@@ -195,7 +195,8 @@ def parse_month(month: Union[str, int]) -> str:
195195
month = int(month)
196196
except ValueError:
197197
try:
198-
return months[month.capitalize()[:3]] # type: ignore
198+
assert not isinstance(month, int)
199+
return months[month.capitalize()[:3]]
199200
except KeyError:
200201
raise ValueError(error_text)
201202

domdf_python_tools/delegators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _f(f: _C) -> _C:
8282
if param in to_params:
8383
del to_params[param]
8484

85-
f.__signature__ = from_sig.replace( # type: ignore
85+
f.__signature__ = from_sig.replace( # type: ignore[attr-defined]
8686
parameters=[*from_params.values(), *to_params.values()]
8787
)
8888
f.__annotations__ = {**to_annotations, **from_annotations}
@@ -116,11 +116,11 @@ def _f(f: _C) -> _C:
116116
from_params = dict(from_sig.parameters)
117117

118118
if tuple(from_params.keys()) == ("args", "kwargs"):
119-
f.__signature__ = to_sig # type: ignore
119+
f.__signature__ = to_sig # type: ignore[attr-defined]
120120
copy_annotations(f)
121121

122122
elif tuple(from_params.keys()) == ("self", "args", "kwargs"):
123-
f.__signature__ = from_sig.replace( # type: ignore
123+
f.__signature__ = from_sig.replace( # type: ignore[attr-defined]
124124
parameters=[from_params["self"], *to_sig.parameters.values()]
125125
)
126126

domdf_python_tools/iterative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,4 @@ def __init_subclass__(cls, **kwargs):
501501

502502
count.__qualname__ = count.__name__ = "count"
503503

504-
return count() # type: ignore
504+
return count() # type: ignore[return-value]

domdf_python_tools/paths.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,19 @@ class PathPlus(pathlib.Path):
388388
__slots__ = ()
389389

390390
if sys.version_info < (3, 11):
391-
_accessor = pathlib._normal_accessor # type: ignore
391+
_accessor = pathlib._normal_accessor # type: ignore[attr-defined]
392392
_closed = False
393393

394394
def _init(self, *args, **kwargs):
395395
pass
396396

397397
@classmethod
398398
def _from_parts(cls, args, init=True):
399-
return super()._from_parts(args) # type: ignore
399+
return super()._from_parts(args) # type: ignore[misc]
400400

401401
def __new__(cls: Type[_PP], *args, **kwargs) -> _PP: # noqa: D102
402402
if cls is PathPlus:
403-
cls = WindowsPathPlus if os.name == "nt" else PosixPathPlus # type: ignore
403+
cls = WindowsPathPlus if os.name == "nt" else PosixPathPlus # type: ignore[assignment]
404404

405405
return super().__new__(cls, *args, **kwargs)
406406

@@ -630,7 +630,7 @@ def dump_json(
630630
data: Any,
631631
encoding: Optional[str] = "UTF-8",
632632
errors: Optional[str] = None,
633-
json_library: JsonLibrary = json, # type: ignore
633+
json_library: JsonLibrary = json, # type: ignore[assignment]
634634
*,
635635
compress: bool = False,
636636
**kwargs,
@@ -674,7 +674,7 @@ def load_json(
674674
self,
675675
encoding: Optional[str] = "UTF-8",
676676
errors: Optional[str] = None,
677-
json_library: JsonLibrary = json, # type: ignore
677+
json_library: JsonLibrary = json, # type: ignore[assignment]
678678
*,
679679
decompress: bool = False,
680680
**kwargs,
@@ -1255,7 +1255,7 @@ def phase4(self) -> None: # noqa: D102
12551255
"right_list": filecmp.dircmp.phase0
12561256
}
12571257

1258-
methodmap = _methodmap # type: ignore
1258+
methodmap = _methodmap # type: ignore[assignment]
12591259

12601260

12611261
def compare_dirs(a: PathLike, b: PathLike) -> bool:

domdf_python_tools/pretty_print.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545

4646
# 3rd party
4747
from pprint36 import PrettyPrinter
48-
from pprint36._pprint import _safe_key # type: ignore
48+
from pprint36._pprint import _safe_key # type: ignore[attr-defined]
4949

5050
supports_sort_dicts = True
5151

5252
except ImportError:
5353

5454
# stdlib
55-
from pprint import PrettyPrinter, _safe_key # type: ignore
55+
from pprint import PrettyPrinter, _safe_key # type: ignore[attr-defined]
5656

5757
supports_sort_dicts = sys.version_info >= (3, 8)
5858

@@ -107,21 +107,21 @@ def __init__(
107107
_dispatch: MutableMapping[Callable, Callable]
108108
_indent_per_level: int
109109
_format_items: ClassVar[Callable[[PrettyPrinter, Any, Any, Any, Any, Any, Any], None]]
110-
_dispatch = dict(PrettyPrinter._dispatch) # type: ignore
110+
_dispatch = dict(PrettyPrinter._dispatch) # type: ignore[attr-defined]
111111

112112
def _make_open(self, char: str, indent: int, obj):
113113
if self._indent_per_level > 1:
114114
the_indent = ' ' * (indent + 1)
115115
else:
116116
the_indent = ' ' * (indent + self._indent_per_level)
117117

118-
if obj and not self._compact: # type: ignore
118+
if obj and not self._compact: # type: ignore[attr-defined]
119119
return f"{char}\n{the_indent}"
120120
else:
121121
return char
122122

123123
def _make_close(self, char: str, indent: int, obj):
124-
if obj and not self._compact: # type: ignore
124+
if obj and not self._compact: # type: ignore[attr-defined]
125125
return f",\n{' ' * (indent + self._indent_per_level)}{char}"
126126
else:
127127
return char
@@ -143,14 +143,14 @@ def _pprint_dict(
143143
write((self._indent_per_level - 1) * ' ')
144144

145145
if obj:
146-
self._format_dict_items( # type: ignore
147-
obj.items(),
148-
stream,
149-
indent,
150-
allowance + 1,
151-
context,
152-
level,
153-
)
146+
self._format_dict_items( # type: ignore[attr-defined]
147+
obj.items(),
148+
stream,
149+
indent,
150+
allowance + 1,
151+
context,
152+
level,
153+
)
154154

155155
write(self._make_close('}', indent, obj))
156156

@@ -243,7 +243,7 @@ def _format_attribute_items(self, items, stream, indent, allowance, context, lev
243243
last = i == last_index
244244
write(key)
245245
write('=')
246-
self._format( # type: ignore
246+
self._format( # type: ignore[attr-defined]
247247
ent,
248248
stream,
249249
indent + len(key) + 2,
@@ -284,7 +284,7 @@ def __repr__(self) -> str:
284284
__repr__.__name__ = "__repr__"
285285
__repr__.__module__ = obj.__module__
286286
__repr__.__qualname__ = f"{obj.__module__}.__repr__"
287-
obj.__repr__ = __repr__ # type: ignore
287+
obj.__repr__ = __repr__ # type: ignore[assignment]
288288

289289
return obj
290290

domdf_python_tools/stringlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def with_indent(self, indent: Union[String, Indent], size: int = 0):
411411
:param size: If ``indent`` is an indent type, the indent size to use within the ``with`` block.
412412
"""
413413

414-
original_indent: Tuple[int, str] = tuple(self.indent) # type: ignore
414+
original_indent: Tuple[int, str] = tuple(self.indent) # type: ignore[assignment]
415415

416416
try:
417417
self.set_indent(indent, size)

domdf_python_tools/terminal.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,22 @@ def __init__(self, indent: str = ' ' * 2):
170170
if frame is None: # pragma: no cover
171171
raise ValueError("Unable to obtain the frame of the caller.")
172172
else:
173-
self.parent_frame = inspect.currentframe().f_back # type: ignore # TODO
173+
self.parent_frame = inspect.currentframe().f_back # type: ignore[union-attr] # TODO
174174

175175
def __enter__(self):
176176
"""
177177
Called when entering the context manager.
178178
"""
179179

180-
self.locals_on_entry = self.parent_frame.f_locals.copy() # type: ignore
180+
self.locals_on_entry = self.parent_frame.f_locals.copy() # type: ignore[union-attr]
181181

182182
def __exit__(self, *args, **kwargs):
183183
"""
184184
Called when exiting the context manager.
185185
"""
186186

187-
new_locals = {
188-
k: v
189-
for k,
190-
v in self.parent_frame.f_locals.items() # type: ignore
191-
if k not in self.locals_on_entry
192-
}
187+
f_locals = self.parent_frame.f_locals # type: ignore[union-attr]
188+
new_locals = {k: v for k, v in f_locals.items() if k not in self.locals_on_entry}
193189

194190
print(textwrap.indent(pprint.pformat(new_locals), self.indent))
195191

domdf_python_tools/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def check_membership(obj: Any, type_: Union[Type, object]) -> bool:
109109
such as a :class:`typing.List`, :py:data:`typing.Union` or :py:class:`typing.Sequence`.
110110
"""
111111

112-
return isinstance(obj, type_.__args__) # type: ignore
112+
return isinstance(obj, type_.__args__) # type: ignore[union-attr]
113113

114114

115115
class JsonLibrary(Protocol):

domdf_python_tools/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ def head(obj: Union[Tuple, List, "DataFrame", "Series", String, HasHead], n: int
444444
elif isinstance(obj, HasHead):
445445
return obj.head(n).to_string()
446446

447-
elif len(obj) <= n: # type: ignore
447+
elif len(obj) <= n: # type: ignore[arg-type]
448448
return str(obj)
449449

450450
else:
451-
return str(obj[:n]) + etc # type: ignore
451+
return str(obj[:n]) + etc # type: ignore[index]
452452

453453

454454
def magnitude(x: float) -> int:
@@ -553,7 +553,7 @@ def divide(string: str, sep: str) -> Tuple[str, str]:
553553
raise ValueError(f"{sep!r} not in {string!r}")
554554

555555
parts = string.split(sep, 1)
556-
return tuple(parts) # type: ignore
556+
return tuple(parts) # type: ignore[return-value]
557557

558558

559559
def redivide(string: str, pat: Union[str, Pattern]) -> Tuple[str, str]:
@@ -577,7 +577,7 @@ def redivide(string: str, pat: Union[str, Pattern]) -> Tuple[str, str]:
577577
raise ValueError(f"{pat!r} has no matches in {string!r}")
578578

579579
parts = pat.split(string, 1)
580-
return tuple(parts) # type: ignore
580+
return tuple(parts) # type: ignore[return-value]
581581

582582

583583
@overload

0 commit comments

Comments
 (0)