From 2a91c633181e7c73cc4423772fffc49c25b5ac18 Mon Sep 17 00:00:00 2001 From: Warren Date: Thu, 24 Aug 2023 09:38:53 +1000 Subject: [PATCH] fix: closes #11343's [attr-defined] type errors On Windows 10.0.19045, the mypy hook is failing on pre-commit because of two [attr-defined] errors, which prevents me from staging stages. The problem was first reported in #11343. This PR solves the problem by adding `type ignore` comments to the erroring lines: ``` src\_pytest\compat.py:324: error: Module has no attribute "getuid"; maybe "getpid" or "getppid"? [attr-defined] testing\test_parseopt.py:294: error: Module has no attribute "getencoding" [attr-defined] ``` --- src/_pytest/compat.py | 2 +- testing/test_parseopt.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index cead6c3113c..08dfeca1b60 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -321,7 +321,7 @@ def get_user_id() -> int | None: return None # getuid shouldn't fail, but cpython defines such a case. # Let's hope for the best. - uid = os.getuid() + uid = os.getuid() # type: ignore[attr-defined] return uid if uid != -1 else None diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 1899abe153f..b6df035aacf 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -291,7 +291,8 @@ def test_multiple_metavar_help(self, parser: parseopt.Parser) -> None: def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: try: - encoding = locale.getencoding() # New in Python 3.11, ignores utf-8 mode + # New in Python 3.11, ignores utf-8 mode + encoding = locale.getencoding() # type: ignore[attr-defined] except AttributeError: encoding = locale.getpreferredencoding(False) try: