From 5e29e4cdac9c582abe62c61abe2ab5f1d947b00b Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 25 Dec 2024 20:45:51 +0100 Subject: [PATCH 1/6] [mypy] Fixes 'Enum members must be left unannotated' --- src/_pytest/scope.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/_pytest/scope.py b/src/_pytest/scope.py index 976a3ba242e..2b007e87893 100644 --- a/src/_pytest/scope.py +++ b/src/_pytest/scope.py @@ -33,11 +33,11 @@ class Scope(Enum): """ # Scopes need to be listed from lower to higher. - Function: _ScopeName = "function" - Class: _ScopeName = "class" - Module: _ScopeName = "module" - Package: _ScopeName = "package" - Session: _ScopeName = "session" + Function = "function" + Class = "class" + Module = "module" + Package = "package" + Session = "session" def next_lower(self) -> Scope: """Return the next lower scope.""" From bea2333de1ef4b52fbd6c0a97346da23de7fb0ca Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 25 Dec 2024 20:56:30 +0100 Subject: [PATCH 2/6] [style] fix shadowed import name 'errno' from outer scope --- src/_pytest/_py/error.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/_pytest/_py/error.py b/src/_pytest/_py/error.py index de0c04a4838..8b7f63d6925 100644 --- a/src/_pytest/_py/error.py +++ b/src/_pytest/_py/error.py @@ -90,15 +90,14 @@ def checked_call( except OSError as value: if not hasattr(value, "errno"): raise - errno = value.errno if sys.platform == "win32": try: - cls = self._geterrnoclass(_winerrnomap[errno]) + cls = self._geterrnoclass(_winerrnomap[value.errno]) except KeyError: raise value else: # we are not on Windows, or we got a proper OSError - cls = self._geterrnoclass(errno) + cls = self._geterrnoclass(value.errno) raise cls(f"{func.__name__}{args!r}") From 977eebe53371828ac7cd8ba2234c9025da31736a Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 25 Dec 2024 20:59:15 +0100 Subject: [PATCH 3/6] [mypy] Fixes 'ErrorMaker._geterrnoclass' Optional[int]; expected int --- src/_pytest/_py/error.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/_pytest/_py/error.py b/src/_pytest/_py/error.py index 8b7f63d6925..e7db4f1c50e 100644 --- a/src/_pytest/_py/error.py +++ b/src/_pytest/_py/error.py @@ -97,6 +97,16 @@ def checked_call( raise value else: # we are not on Windows, or we got a proper OSError + # Not sure if we should do that: + # if errno is None: + # clsname = errno.errorcode.get(errno, f"UnknownErrno{errno}") + # cls = type( + # clsname, + # (Error,), + # {"__module__": "py.error", "__doc__": os.strerror(errno)}, + # ) + # Or that: + assert isinstance(value.errno, int) cls = self._geterrnoclass(value.errno) raise cls(f"{func.__name__}{args!r}") From da84b468f3f6a3b1fc94bf174080d6ea72ad5751 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 25 Dec 2024 21:27:47 +0100 Subject: [PATCH 4/6] [mypy] noqa false positive in NamespaceLoader --- src/_pytest/pathlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 25dc69b6349..c52c6829c67 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -711,7 +711,7 @@ def _import_module_using_spec( if module_path.is_dir(): # The `spec_from_file_location` matches a loader based on the file extension by default. # For a namespace package, need to manually specify a loader. - loader = NamespaceLoader(name, module_path, PathFinder()) + loader = NamespaceLoader(name, module_path, PathFinder()) # type: ignore[arg-type] spec = importlib.util.spec_from_file_location( module_name, str(module_path), loader=loader From 4dda87c99dc9d476f07d59d523d2206cce4cc9d8 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 25 Dec 2024 21:28:46 +0100 Subject: [PATCH 5/6] [mypy] Proper typing of mixed type string wrapper --- testing/io/test_terminalwriter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/io/test_terminalwriter.py b/testing/io/test_terminalwriter.py index f14e884b1f0..1f38d6f15d9 100644 --- a/testing/io/test_terminalwriter.py +++ b/testing/io/test_terminalwriter.py @@ -3,6 +3,7 @@ from collections.abc import Generator import io +from io import StringIO import os from pathlib import Path import re @@ -68,6 +69,7 @@ def test_terminalwriter_not_unicode() -> None: class TestTerminalWriter: @pytest.fixture(params=["path", "stringio"]) def tw(self, request, tmp_path: Path) -> Generator[terminalwriter.TerminalWriter]: + f: io.TextIOWrapper | StringIO if request.param == "path": p = tmp_path.joinpath("tmpfile") f = open(str(p), "w+", encoding="utf8") From 35f13c6c6651b4fd591286ed5ce0c8aaebdbe448 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 23:18:43 +0000 Subject: [PATCH 6/6] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.3 → v0.8.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.3...v0.8.4) - [github.com/woodruffw/zizmor-pre-commit: v0.9.2 → v0.10.0](https://github.com/woodruffw/zizmor-pre-commit/compare/v0.9.2...v0.10.0) - [github.com/pre-commit/mirrors-mypy: v1.13.0 → v1.14.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.13.0...v1.14.0) - [github.com/asottile/pyupgrade: v3.19.0 → v3.19.1](https://github.com/asottile/pyupgrade/compare/v3.19.0...v3.19.1) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d7a4efabe98..9ad3c8e9f81 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.8.3" + rev: "v0.8.4" hooks: - id: ruff args: ["--fix"] @@ -12,7 +12,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/woodruffw/zizmor-pre-commit - rev: v0.9.2 + rev: v0.10.0 hooks: - id: zizmor - repo: https://github.com/adamchainz/blacken-docs @@ -32,7 +32,7 @@ repos: hooks: - id: python-use-type-annotations - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.13.0 + rev: v1.14.0 hooks: - id: mypy files: ^(src/|testing/|scripts/) @@ -54,7 +54,7 @@ repos: # https://pyproject-fmt.readthedocs.io/en/latest/#calculating-max-supported-python-version additional_dependencies: ["tox>=4.9"] - repo: https://github.com/asottile/pyupgrade - rev: v3.19.0 + rev: v3.19.1 hooks: - id: pyupgrade args: