Skip to content

Commit

Permalink
fix: closes pytest-dev#11343's [attr-defined] type errors
Browse files Browse the repository at this point in the history
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 pytest-dev#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]
```
  • Loading branch information
WarrenTheRabbit committed Aug 23, 2023
1 parent 37bb186 commit 2a91c63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/_pytest/compat.py
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion testing/test_parseopt.py
Expand Up @@ -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:
Expand Down

0 comments on commit 2a91c63

Please sign in to comment.