From 4fce29f15d88a30d655c701e503a4ecb6920e289 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Nov 2022 00:17:06 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.2.0 → v3.2.2](https://github.com/asottile/pyupgrade/compare/v3.2.0...v3.2.2) - [github.com/pre-commit/mirrors-mypy: v0.982 → v0.990](https://github.com/pre-commit/mirrors-mypy/compare/v0.982...v0.990) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ab6c6d3e..cff5546d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,7 +44,7 @@ repos: - id: reorder-python-imports args: ['--application-directories=.:src', --py37-plus] - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 + rev: v3.2.2 hooks: - id: pyupgrade args: [--py37-plus] @@ -58,7 +58,7 @@ repos: hooks: - id: python-use-type-annotations - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v0.990 hooks: - id: mypy files: ^(src/|testing/) From d5466b39173a62fbcbe0dd2554ede7781a6ae759 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 15 Nov 2022 08:53:23 -0300 Subject: [PATCH 2/2] Fix typing errors after mypy update --- src/_pytest/_py/path.py | 11 ++++++----- src/_pytest/hookspec.py | 10 ++++++---- testing/_py/test_local.py | 6 +++--- testing/test_monkeypatch.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index 00f151523..c3905d0d3 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -24,6 +24,7 @@ from stat import S_ISLNK from stat import S_ISREG from typing import Any from typing import Callable +from typing import cast from typing import overload from typing import TYPE_CHECKING @@ -146,7 +147,7 @@ class Visitor: self.fil = fil self.ignore = ignore self.breadthfirst = bf - self.optsort = sort and sorted or (lambda x: x) + self.optsort = cast(Callable[[Any], Any], sorted) if sort else (lambda x: x) def gen(self, path): try: @@ -224,7 +225,7 @@ class Stat: raise NotImplementedError("XXX win32") import pwd - entry = error.checked_call(pwd.getpwuid, self.uid) + entry = error.checked_call(pwd.getpwuid, self.uid) # type:ignore[attr-defined] return entry[0] @property @@ -234,7 +235,7 @@ class Stat: raise NotImplementedError("XXX win32") import grp - entry = error.checked_call(grp.getgrgid, self.gid) + entry = error.checked_call(grp.getgrgid, self.gid) # type:ignore[attr-defined] return entry[0] def isdir(self): @@ -252,7 +253,7 @@ def getuserid(user): import pwd if not isinstance(user, int): - user = pwd.getpwnam(user)[2] + user = pwd.getpwnam(user)[2] # type:ignore[attr-defined] return user @@ -260,7 +261,7 @@ def getgroupid(group): import grp if not isinstance(group, int): - group = grp.getgrnam(group)[2] + group = grp.getgrnam(group)[2] # type:ignore[attr-defined] return group diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index cc0828dd1..446f580ee 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -738,7 +738,7 @@ def pytest_assertion_pass(item: "Item", lineno: int, orig: str, expl: str) -> No # ------------------------------------------------------------------------- -def pytest_report_header( +def pytest_report_header( # type:ignore[empty-body] config: "Config", start_path: Path, startdir: "LEGACY_PATH" ) -> Union[str, List[str]]: """Return a string or list of strings to be displayed as header info for terminal reporting. @@ -767,7 +767,7 @@ def pytest_report_header( """ -def pytest_report_collectionfinish( +def pytest_report_collectionfinish( # type:ignore[empty-body] config: "Config", start_path: Path, startdir: "LEGACY_PATH", @@ -800,7 +800,7 @@ def pytest_report_collectionfinish( @hookspec(firstresult=True) -def pytest_report_teststatus( +def pytest_report_teststatus( # type:ignore[empty-body] report: Union["CollectReport", "TestReport"], config: "Config" ) -> Tuple[str, str, Union[str, Mapping[str, bool]]]: """Return result-category, shortletter and verbose word for status @@ -880,7 +880,9 @@ def pytest_warning_recorded( # ------------------------------------------------------------------------- -def pytest_markeval_namespace(config: "Config") -> Dict[str, Any]: +def pytest_markeval_namespace( # type:ignore[empty-body] + config: "Config", +) -> Dict[str, Any]: """Called when constructing the globals dictionary used for evaluating string conditions in xfail/skipif markers. diff --git a/testing/_py/test_local.py b/testing/_py/test_local.py index 31c10b160..b463d769d 100644 --- a/testing/_py/test_local.py +++ b/testing/_py/test_local.py @@ -803,7 +803,7 @@ class TestLocalPath(CommonFSTests): # depending on how the paths are used), but > 4096 (which is the # Linux' limitation) - the behaviour of paths with names > 4096 chars # is undetermined - newfilename = "/test" * 60 + newfilename = "/test" * 60 # type:ignore[unreachable] l1 = tmpdir.join(newfilename) l1.ensure(file=True) l1.write("foo") @@ -1344,8 +1344,8 @@ class TestPOSIXLocalPath: assert realpath.basename == "file" def test_owner(self, path1, tmpdir): - from pwd import getpwuid - from grp import getgrgid + from pwd import getpwuid # type:ignore[attr-defined] + from grp import getgrgid # type:ignore[attr-defined] stat = path1.stat() assert stat.path == path1 diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 49635f95e..b32e67bd7 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -92,7 +92,7 @@ class TestSetattrWithImportPath: mp.delattr("os.path.abspath") assert not hasattr(os.path, "abspath") mp.undo() - assert os.path.abspath + assert os.path.abspath # type:ignore[truthy-function] def test_delattr() -> None: