Skip to content

Commit f61d4ed

Browse files
authored
Merge pull request #7907 from bluetech/mypy-790
Update mypy 0.782 -> 0.790, iniconfig typing
2 parents 0a258f5 + 09e38b1 commit f61d4ed

14 files changed

+28
-30
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ repos:
4949
hooks:
5050
- id: python-use-type-annotations
5151
- repo: https://github.com/pre-commit/mirrors-mypy
52-
rev: v0.782 # NOTE: keep this in sync with setup.cfg.
52+
rev: v0.790 # NOTE: keep this in sync with setup.cfg.
5353
hooks:
5454
- id: mypy
5555
files: ^(src/|testing/)
5656
args: []
57+
additional_dependencies:
58+
- iniconfig>=1.1.0
5759
- repo: local
5860
hooks:
5961
- id: rst

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ console_scripts =
6363

6464
[options.extras_require]
6565
checkqa-mypy =
66-
mypy==0.780
66+
mypy==0.790
6767
testing =
6868
argcomplete
6969
hypothesis>=3.56

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def pytest_collection_modifyitems(
382382
self.cached_nodeids.update(item.nodeid for item in items)
383383

384384
def _get_increasing_order(self, items: Iterable[nodes.Item]) -> List[nodes.Item]:
385-
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
385+
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True) # type: ignore[no-any-return]
386386

387387
def pytest_sessionfinish(self) -> None:
388388
config = self.config

src/_pytest/capture.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ def __init__(self, targetfd: int) -> None:
380380
self.syscapture = SysCapture(targetfd)
381381
else:
382382
self.tmpfile = EncodedFile(
383-
# TODO: Remove type ignore, fixed in next mypy release.
384-
TemporaryFile(buffering=0), # type: ignore[arg-type]
383+
TemporaryFile(buffering=0),
385384
encoding="utf-8",
386385
errors="replace",
387386
newline="",

src/_pytest/compat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ def getfuncargnames(
150150
p.name
151151
for p in parameters.values()
152152
if (
153-
# TODO: Remove type ignore after https://github.com/python/typeshed/pull/4383
154-
p.kind is Parameter.POSITIONAL_OR_KEYWORD # type: ignore[unreachable]
155-
or p.kind is Parameter.KEYWORD_ONLY # type: ignore[unreachable]
153+
p.kind is Parameter.POSITIONAL_OR_KEYWORD
154+
or p.kind is Parameter.KEYWORD_ONLY
156155
)
157156
and p.default is Parameter.empty
158157
)

src/_pytest/config/findpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
2727
Raise UsageError if the file cannot be parsed.
2828
"""
2929
try:
30-
return iniconfig.IniConfig(path)
30+
return iniconfig.IniConfig(str(path))
3131
except iniconfig.ParseError as exc:
3232
raise UsageError(str(exc)) from exc
3333

src/_pytest/pytester.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import attr
3333
import py
3434
from iniconfig import IniConfig
35+
from iniconfig import SectionWrapper
3536

3637
import pytest
3738
from _pytest import timing
@@ -785,10 +786,10 @@ def makeini(self, source: str) -> Path:
785786
"""Write a tox.ini file with 'source' as contents."""
786787
return self.makefile(".ini", tox=source)
787788

788-
def getinicfg(self, source: str) -> IniConfig:
789+
def getinicfg(self, source: str) -> SectionWrapper:
789790
"""Return the pytest section from the tox.ini config file."""
790791
p = self.makeini(source)
791-
return IniConfig(p)["pytest"]
792+
return IniConfig(str(p))["pytest"]
792793

793794
def makepyprojecttoml(self, source: str) -> Path:
794795
"""Write a pyproject.toml file with 'source' as contents.
@@ -1321,8 +1322,10 @@ def run(
13211322
"""
13221323
__tracebackhide__ = True
13231324

1325+
# TODO: Remove type ignore in next mypy release.
1326+
# https://github.com/python/typeshed/pull/4582
13241327
cmdargs = tuple(
1325-
os.fspath(arg) if isinstance(arg, os.PathLike) else arg for arg in cmdargs
1328+
os.fspath(arg) if isinstance(arg, os.PathLike) else arg for arg in cmdargs # type: ignore[misc]
13261329
)
13271330
p1 = self.path.joinpath("stdout")
13281331
p2 = self.path.joinpath("stderr")
@@ -1541,9 +1544,9 @@ def makeini(self, source) -> py.path.local:
15411544
"""See :meth:`Pytester.makeini`."""
15421545
return py.path.local(str(self._pytester.makeini(source)))
15431546

1544-
def getinicfg(self, source) -> py.path.local:
1547+
def getinicfg(self, source: str) -> SectionWrapper:
15451548
"""See :meth:`Pytester.getinicfg`."""
1546-
return py.path.local(str(self._pytester.getinicfg(source)))
1549+
return self._pytester.getinicfg(source)
15471550

15481551
def makepyprojecttoml(self, source) -> py.path.local:
15491552
"""See :meth:`Pytester.makepyprojecttoml`."""

src/_pytest/python_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __repr__(self) -> str:
210210
# tolerances, i.e. non-numerics and infinities. Need to call abs to
211211
# handle complex numbers, e.g. (inf + 1j).
212212
if (not isinstance(self.expected, (Complex, Decimal))) or math.isinf(
213-
abs(self.expected)
213+
abs(self.expected) # type: ignore[arg-type]
214214
):
215215
return str(self.expected)
216216

@@ -253,16 +253,16 @@ def __eq__(self, actual) -> bool:
253253
# Allow the user to control whether NaNs are considered equal to each
254254
# other or not. The abs() calls are for compatibility with complex
255255
# numbers.
256-
if math.isnan(abs(self.expected)):
257-
return self.nan_ok and math.isnan(abs(actual))
256+
if math.isnan(abs(self.expected)): # type: ignore[arg-type]
257+
return self.nan_ok and math.isnan(abs(actual)) # type: ignore[arg-type]
258258

259259
# Infinity shouldn't be approximately equal to anything but itself, but
260260
# if there's a relative tolerance, it will be infinite and infinity
261261
# will seem approximately equal to everything. The equal-to-itself
262262
# case would have been short circuited above, so here we can just
263263
# return false if the expected value is infinite. The abs() call is
264264
# for compatibility with complex numbers.
265-
if math.isinf(abs(self.expected)):
265+
if math.isinf(abs(self.expected)): # type: ignore[arg-type]
266266
return False
267267

268268
# Return true if the two numbers are within the tolerance.

src/_pytest/runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def pytest_terminal_summary(terminalreporter: "TerminalReporter") -> None:
7777
dlist.append(rep)
7878
if not dlist:
7979
return
80-
dlist.sort(key=lambda x: x.duration)
81-
dlist.reverse()
80+
dlist.sort(key=lambda x: x.duration, reverse=True) # type: ignore[no-any-return]
8281
if not durations:
8382
tr.write_sep("=", "slowest durations")
8483
else:

testing/test_assertrewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ def test_get_cache_dir(self, monkeypatch, prefix, source, expected):
15951595
if prefix:
15961596
if sys.version_info < (3, 8):
15971597
pytest.skip("pycache_prefix not available in py<38")
1598-
monkeypatch.setattr(sys, "pycache_prefix", prefix) # type:ignore
1598+
monkeypatch.setattr(sys, "pycache_prefix", prefix)
15991599

16001600
assert get_cache_dir(Path(source)) == Path(expected)
16011601

0 commit comments

Comments
 (0)