Skip to content

Commit c0532dd

Browse files
pre-commit-ci[bot]Pierre-Sassoulasbluetech
authored
[pre-commit.ci] pre-commit autoupdate (#12115)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <[email protected]> Co-authored-by: Ran Benita <[email protected]>
1 parent 1443778 commit c0532dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+185
-212
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.2.2"
3+
rev: "v0.3.2"
44
hooks:
55
- id: ruff
66
args: ["--fix"]
@@ -26,7 +26,7 @@ repos:
2626
hooks:
2727
- id: python-use-type-annotations
2828
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.8.0
29+
rev: v1.9.0
3030
hooks:
3131
- id: mypy
3232
files: ^(src/|testing/|scripts/)

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ template = "changelog/_template.rst"
281281
showcontent = true
282282

283283
[tool.mypy]
284+
files = ["src", "testing", "scripts"]
284285
mypy_path = ["src"]
285286
check_untyped_defs = true
286287
disallow_any_generics = true
@@ -293,3 +294,4 @@ warn_return_any = true
293294
warn_unreachable = true
294295
warn_unused_configs = true
295296
no_implicit_reexport = true
297+
warn_unused_ignores = true

scripts/generate-gh-release-notes.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
Requires Python3.6+.
1010
"""
11+
1112
from pathlib import Path
1213
import re
1314
import sys

scripts/prepare-release-pr.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**Token**: currently the token from the GitHub Actions is used, pushed with
1414
`pytest bot <[email protected]>` commit author.
1515
"""
16+
1617
import argparse
1718
from pathlib import Path
1819
import re

scripts/release.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: disallow-untyped-defs
22
"""Invoke development tasks."""
3+
34
import argparse
45
import os
56
from pathlib import Path

src/_pytest/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# broken installation, we don't even try
88
# unknown only works because we do poor mans version compare
99
__version__ = "unknown"
10-
version_tuple = (0, 0, "unknown") # type:ignore[assignment]
10+
version_tuple = (0, 0, "unknown")

src/_pytest/_code/code.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ def ishidden(self, excinfo: Optional["ExceptionInfo[BaseException]"]) -> bool:
279279
280280
Mostly for internal use.
281281
"""
282-
tbh: Union[
283-
bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]
284-
] = False
282+
tbh: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]] = (
283+
False
284+
)
285285
for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals):
286286
# in normal cases, f_locals and f_globals are dictionaries
287287
# however via `exec(...)` / `eval(...)` they can be other types
@@ -378,12 +378,10 @@ def cut(
378378
return self
379379

380380
@overload
381-
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry:
382-
...
381+
def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: ...
383382

384383
@overload
385-
def __getitem__(self, key: slice) -> "Traceback":
386-
...
384+
def __getitem__(self, key: slice) -> "Traceback": ...
387385

388386
def __getitem__(
389387
self, key: Union["SupportsIndex", slice]
@@ -1051,13 +1049,13 @@ def repr_excinfo(
10511049
# full support for exception groups added to ExceptionInfo.
10521050
# See https://github.com/pytest-dev/pytest/issues/9159
10531051
if isinstance(e, BaseExceptionGroup):
1054-
reprtraceback: Union[
1055-
ReprTracebackNative, ReprTraceback
1056-
] = ReprTracebackNative(
1057-
traceback.format_exception(
1058-
type(excinfo_.value),
1059-
excinfo_.value,
1060-
excinfo_.traceback[0]._rawentry,
1052+
reprtraceback: Union[ReprTracebackNative, ReprTraceback] = (
1053+
ReprTracebackNative(
1054+
traceback.format_exception(
1055+
type(excinfo_.value),
1056+
excinfo_.value,
1057+
excinfo_.traceback[0]._rawentry,
1058+
)
10611059
)
10621060
)
10631061
else:
@@ -1348,7 +1346,7 @@ def getfslineno(obj: object) -> Tuple[Union[str, Path], int]:
13481346
# in 6ec13a2b9. It ("place_as") appears to be something very custom.
13491347
obj = get_real_func(obj)
13501348
if hasattr(obj, "place_as"):
1351-
obj = obj.place_as # type: ignore[attr-defined]
1349+
obj = obj.place_as
13521350

13531351
try:
13541352
code = Code.from_function(obj)

src/_pytest/_code/source.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ def __eq__(self, other: object) -> bool:
4747
__hash__ = None # type: ignore
4848

4949
@overload
50-
def __getitem__(self, key: int) -> str:
51-
...
50+
def __getitem__(self, key: int) -> str: ...
5251

5352
@overload
54-
def __getitem__(self, key: slice) -> "Source":
55-
...
53+
def __getitem__(self, key: slice) -> "Source": ...
5654

5755
def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]:
5856
if isinstance(key, int):

src/_pytest/_io/terminalwriter.py

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Sequence
1010
from typing import TextIO
1111

12+
from ..compat import assert_never
1213
from .wcwidth import wcswidth
1314

1415

@@ -209,6 +210,8 @@ def _highlight(
209210
from pygments.lexers.python import PythonLexer as Lexer
210211
elif lexer == "diff":
211212
from pygments.lexers.diff import DiffLexer as Lexer
213+
else:
214+
assert_never(lexer)
212215
from pygments import highlight
213216
import pygments.util
214217
except ImportError:

src/_pytest/_py/path.py

+12-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: allow-untyped-defs
22
"""local path implementation."""
3+
34
from __future__ import annotations
45

56
import atexit
@@ -205,12 +206,10 @@ class Stat:
205206
if TYPE_CHECKING:
206207

207208
@property
208-
def size(self) -> int:
209-
...
209+
def size(self) -> int: ...
210210

211211
@property
212-
def mtime(self) -> float:
213-
...
212+
def mtime(self) -> float: ...
214213

215214
def __getattr__(self, name: str) -> Any:
216215
return getattr(self._osstatresult, "st_" + name)
@@ -225,7 +224,7 @@ def owner(self):
225224
raise NotImplementedError("XXX win32")
226225
import pwd
227226

228-
entry = error.checked_call(pwd.getpwuid, self.uid) # type:ignore[attr-defined]
227+
entry = error.checked_call(pwd.getpwuid, self.uid) # type:ignore[attr-defined,unused-ignore]
229228
return entry[0]
230229

231230
@property
@@ -235,7 +234,7 @@ def group(self):
235234
raise NotImplementedError("XXX win32")
236235
import grp
237236

238-
entry = error.checked_call(grp.getgrgid, self.gid) # type:ignore[attr-defined]
237+
entry = error.checked_call(grp.getgrgid, self.gid) # type:ignore[attr-defined,unused-ignore]
239238
return entry[0]
240239

241240
def isdir(self):
@@ -253,15 +252,15 @@ def getuserid(user):
253252
import pwd
254253

255254
if not isinstance(user, int):
256-
user = pwd.getpwnam(user)[2] # type:ignore[attr-defined]
255+
user = pwd.getpwnam(user)[2] # type:ignore[attr-defined,unused-ignore]
257256
return user
258257

259258

260259
def getgroupid(group):
261260
import grp
262261

263262
if not isinstance(group, int):
264-
group = grp.getgrnam(group)[2] # type:ignore[attr-defined]
263+
group = grp.getgrnam(group)[2] # type:ignore[attr-defined,unused-ignore]
265264
return group
266265

267266

@@ -318,7 +317,7 @@ def chown(self, user, group, rec=0):
318317
def readlink(self) -> str:
319318
"""Return value of a symbolic link."""
320319
# https://github.com/python/mypy/issues/12278
321-
return error.checked_call(os.readlink, self.strpath) # type: ignore[arg-type,return-value]
320+
return error.checked_call(os.readlink, self.strpath) # type: ignore[arg-type,return-value,unused-ignore]
322321

323322
def mklinkto(self, oldname):
324323
"""Posix style hard link to another name."""
@@ -757,15 +756,11 @@ def open(self, mode="r", ensure=False, encoding=None):
757756
if ensure:
758757
self.dirpath().ensure(dir=1)
759758
if encoding:
760-
# Using type ignore here because of this error:
761-
# error: Argument 1 has incompatible type overloaded function;
762-
# expected "Callable[[str, Any, Any], TextIOWrapper]" [arg-type]
763-
# Which seems incorrect, given io.open supports the given argument types.
764759
return error.checked_call(
765760
io.open,
766761
self.strpath,
767762
mode,
768-
encoding=encoding, # type:ignore[arg-type]
763+
encoding=encoding,
769764
)
770765
return error.checked_call(open, self.strpath, mode)
771766

@@ -966,12 +961,10 @@ def ensure(self, *args, **kwargs):
966961
return p
967962

968963
@overload
969-
def stat(self, raising: Literal[True] = ...) -> Stat:
970-
...
964+
def stat(self, raising: Literal[True] = ...) -> Stat: ...
971965

972966
@overload
973-
def stat(self, raising: Literal[False]) -> Stat | None:
974-
...
967+
def stat(self, raising: Literal[False]) -> Stat | None: ...
975968

976969
def stat(self, raising: bool = True) -> Stat | None:
977970
"""Return an os.stat() tuple."""
@@ -1277,13 +1270,7 @@ def mkdtemp(cls, rootdir=None):
12771270

12781271
if rootdir is None:
12791272
rootdir = cls.get_temproot()
1280-
# Using type ignore here because of this error:
1281-
# error: Argument 1 has incompatible type overloaded function; expected "Callable[[str], str]" [arg-type]
1282-
# Which seems incorrect, given tempfile.mkdtemp supports the given argument types.
1283-
path = error.checked_call(
1284-
tempfile.mkdtemp,
1285-
dir=str(rootdir), # type:ignore[arg-type]
1286-
)
1273+
path = error.checked_call(tempfile.mkdtemp, dir=str(rootdir))
12871274
return cls(path)
12881275

12891276
@classmethod

src/_pytest/assertion/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: allow-untyped-defs
22
"""Support for presenting detailed information in failing assertions."""
3+
34
import sys
45
from typing import Any
56
from typing import Generator

src/_pytest/assertion/rewrite.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,13 @@ def get_data(self, pathname: Union[str, bytes]) -> bytes:
289289
else:
290290
from importlib.abc import TraversableResources
291291

292-
def get_resource_reader(self, name: str) -> TraversableResources: # type: ignore
292+
def get_resource_reader(self, name: str) -> TraversableResources:
293293
if sys.version_info < (3, 11):
294294
from importlib.readers import FileReader
295295
else:
296296
from importlib.resources.readers import FileReader
297297

298-
return FileReader( # type:ignore[no-any-return]
299-
types.SimpleNamespace(path=self._rewritten_names[name])
300-
)
298+
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))
301299

302300

303301
def _write_pyc_fp(
@@ -672,9 +670,9 @@ def __init__(
672670
self.enable_assertion_pass_hook = False
673671
self.source = source
674672
self.scope: tuple[ast.AST, ...] = ()
675-
self.variables_overwrite: defaultdict[
676-
tuple[ast.AST, ...], Dict[str, str]
677-
] = defaultdict(dict)
673+
self.variables_overwrite: defaultdict[tuple[ast.AST, ...], Dict[str, str]] = (
674+
defaultdict(dict)
675+
)
678676

679677
def run(self, mod: ast.Module) -> None:
680678
"""Find all assert statements in *mod* and rewrite them."""
@@ -975,7 +973,7 @@ def visit_NamedExpr(self, name: ast.NamedExpr) -> Tuple[ast.NamedExpr, str]:
975973
# name if it's a local variable or _should_repr_global_name()
976974
# thinks it's acceptable.
977975
locs = ast.Call(self.builtin("locals"), [], [])
978-
target_id = name.target.id # type: ignore[attr-defined]
976+
target_id = name.target.id
979977
inlocs = ast.Compare(ast.Constant(target_id), [ast.In()], [locs])
980978
dorepr = self.helper("_should_repr_global_name", name)
981979
test = ast.BoolOp(ast.Or(), [inlocs, dorepr])

src/_pytest/assertion/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: allow-untyped-defs
22
"""Utilities for assertion debugging."""
3+
34
import collections.abc
45
import os
56
import pprint
@@ -222,10 +223,9 @@ def assertrepr_compare(
222223
except outcomes.Exit:
223224
raise
224225
except Exception:
226+
repr_crash = _pytest._code.ExceptionInfo.from_current()._getreprcrash()
225227
explanation = [
226-
"(pytest_assertion plugin: representation of details failed: {}.".format(
227-
_pytest._code.ExceptionInfo.from_current()._getreprcrash()
228-
),
228+
f"(pytest_assertion plugin: representation of details failed: {repr_crash}.",
229229
" Probably an object has a faulty __repr__.)",
230230
]
231231

src/_pytest/cacheprovider.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mypy: allow-untyped-defs
22
"""Implementation of the cache provider."""
3+
34
# This plugin was not named "cache" to avoid conflicts with the external
45
# pytest-cache version.
56
import dataclasses
@@ -432,7 +433,7 @@ def pytest_collection_modifyitems(
432433
return res
433434

434435
def _get_increasing_order(self, items: Iterable[nodes.Item]) -> List[nodes.Item]:
435-
return sorted(items, key=lambda item: item.path.stat().st_mtime, reverse=True) # type: ignore[no-any-return]
436+
return sorted(items, key=lambda item: item.path.stat().st_mtime, reverse=True)
436437

437438
def pytest_sessionfinish(self) -> None:
438439
config = self.config

0 commit comments

Comments
 (0)