Skip to content

Commit 21fd25a

Browse files
committed
Bump mypy version.
1 parent 1f207df commit 21fd25a

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

domdf_python_tools/paths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ class TemporaryPathPlus(tempfile.TemporaryDirectory):
11191119
.. autosummary-widths:: 6/16
11201120
"""
11211121

1122-
name: PathPlus # type: ignore
1122+
name: PathPlus
11231123
"""
11241124
The temporary directory itself.
11251125

domdf_python_tools/stringlist.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
# stdlib
3434
from contextlib import contextmanager
3535
from itertools import chain
36-
from typing import Any, Iterable, Iterator, List, Tuple, TypeVar, Union, cast, overload
36+
from typing import Any, Iterable, Iterator, List, Reversible, Tuple, TypeVar, Union, cast, overload
3737

3838
# this package
3939
from domdf_python_tools.doctools import prettify_docstrings
40-
from domdf_python_tools.typing import String
40+
from domdf_python_tools.typing import String, SupportsIndex
4141
from domdf_python_tools.utils import convert_indents
4242

4343
__all__ = ["Indent", "StringList", "DelimitedList", "_SL", "splitlines", "joinlines"]
@@ -202,16 +202,20 @@ def count_blanklines(self) -> int:
202202

203203
return self.count('')
204204

205-
def insert(self, index: int, line: String) -> None:
205+
def insert(self, index: SupportsIndex, line: String) -> None:
206206
"""
207207
Insert a line into the :class:`~domdf_python_tools.stringlist.StringList` at the given position.
208208
209209
:param index:
210210
:param line:
211+
212+
.. versionchanged:: 3.2.0 Changed :class:`int` in the type annotation to :protocol:`~.SupportsIndex`.
211213
"""
212214

213215
lines: List[str]
214216

217+
index = index.__index__()
218+
215219
if index < 0 or index > len(self):
216220
lines = str(line).split('\n')
217221
else:
@@ -221,12 +225,12 @@ def insert(self, index: int, line: String) -> None:
221225
super().insert(index, self._make_line(inner_line))
222226

223227
@overload
224-
def __setitem__(self, index: int, line: String) -> None: ...
228+
def __setitem__(self, index: SupportsIndex, line: String) -> None: ...
225229

226230
@overload
227231
def __setitem__(self, index: slice, line: Iterable[String]) -> None: ...
228232

229-
def __setitem__(self, index: Union[int, slice], line: Union[String, Iterable[String]]):
233+
def __setitem__(self, index: Union[SupportsIndex, slice], line: Union[String, Iterable[String]]):
230234
"""
231235
Replaces the given line with new content.
232236
@@ -235,29 +239,39 @@ def __setitem__(self, index: Union[int, slice], line: Union[String, Iterable[Str
235239
236240
:param index:
237241
:param line:
242+
243+
.. versionchanged:: 3.2.0 Changed :class:`int` in the type annotation to :protocol:`~.SupportsIndex`.
238244
"""
239245

240-
if isinstance(index, int):
246+
if isinstance(index, slice):
247+
line = cast(Iterable[String], line)
248+
249+
if not isinstance(line, Reversible):
250+
line = tuple(line)
251+
252+
for lline, idx in zip(
253+
reversed(line),
254+
reversed(range(index.start or 0, index.stop + 1, index.step or 1)),
255+
):
256+
self[idx] = lline
257+
else:
258+
line = cast(String, line)
259+
index = index.__index__()
260+
241261
if self and index < len(self):
242262
self.pop(index)
243263
if index < 0:
244264
index = len(self) + index + 1
245-
self.insert(index, line)
246265

247-
elif isinstance(index, slice):
248-
for line, idx in zip( # pylint: disable=redefined-argument-from-local
249-
reversed(line), # type: ignore
250-
reversed(range(index.start or 0, index.stop + 1, index.step or 1)),
251-
):
252-
self[idx] = line
266+
self.insert(index, line)
253267

254268
@overload
255-
def __getitem__(self, index: int) -> str: ...
269+
def __getitem__(self, index: SupportsIndex) -> str: ...
256270

257271
@overload
258272
def __getitem__(self: _SL, index: slice) -> _SL: ...
259273

260-
def __getitem__(self: _SL, index: Union[int, slice]) -> Union[str, _SL]:
274+
def __getitem__(self: _SL, index: Union[SupportsIndex, slice]) -> Union[str, _SL]:
261275
r"""
262276
Returns the line with the given index.
263277
@@ -268,6 +282,8 @@ def __getitem__(self: _SL, index: Union[int, slice]) -> Union[str, _SL]:
268282
.. versionchanged:: 1.8.0
269283
270284
Now returns a :class:`~domdf_python_tools.stringlist.StringList` when ``index`` is a :class:`slice`.
285+
286+
.. versionchanged:: 3.2.0 Changed :class:`int` in the type annotation to :protocol:`~.SupportsIndex`.
271287
"""
272288

273289
if isinstance(index, slice):

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ignore_errors = True
8282
changedir = {toxinidir}
8383
extras = all
8484
deps =
85-
mypy==0.812
85+
mypy==0.910
8686
-r{toxinidir}/tests/requirements.txt
8787
-r{toxinidir}/stubs.txt
8888
pprint36

0 commit comments

Comments
 (0)