Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit failing on mypy hook with at least a 'Module has no attribute "getuid" error' #11343

Closed
WarrenTheRabbit opened this issue Aug 23, 2023 · 1 comment

Comments

@WarrenTheRabbit
Copy link
Contributor

description of problem

On VS Code, I am attempting to commit a staged change of src\_pytest\config\__init__.py; however, the pre-commit hook fails on mypy with command ouput:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

src\_pytest\compat.py:324: error: Module has no attribute "getuid"; maybe "getpid" or "getppid"?  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Every other hook either passes or is skipped. I installed pre-commit and its hook on the pytest repo using

$ pip install --user pre-commit
$ pre-commit install

pip list output

(.venv) PS C:\pytest\pytest> pip list
Package            Version                           Editable project location
------------------ --------------------------------- -------------------------
argcomplete        3.1.1
attrs              23.1.0
cachetools         5.3.1
certifi            2023.7.22
cfgv               3.4.0
chardet            5.2.0
charset-normalizer 3.2.0
colorama           0.4.6
distlib            0.3.7
elementpath        4.1.5
exceptiongroup     1.1.3
filelock           3.12.2
hypothesis         6.82.6
identify           2.5.26
idna               3.4
iniconfig          2.0.0
mock               5.1.0
nodeenv            1.8.0
nose               1.3.7
packaging          23.1
pip                23.2.1
platformdirs       3.10.0
pluggy             1.2.0
pre-commit         3.3.3
Pygments           2.16.1
pyproject-api      1.5.4
pytest             8.0.0.dev167+g37bb18617.d20230822 C:\pytest\pytest
PyYAML             6.0.1
requests           2.31.0
setuptools         58.1.0
sortedcontainers   2.4.0
tomli              2.0.1
tox                4.9.0
urllib3            2.0.4
virtualenv         20.24.3
xmlschema          2.4.0

pytest and operating system versions

$ pytest --version
$ pytest 8.0.0.dev167+g37bb18617.d20230822
>>> platform.system(), platform.release(), platform.version()  
('Windows', '10', '10.0.19045')

minimal example

If I discard my changes and do pre-commit run --all-files, everything passes or is skipped except for

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

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]
Found 2 errors in 2 files (checked 224 source files)
@WarrenTheRabbit
Copy link
Contributor Author

WarrenTheRabbit commented Aug 23, 2023

I've noticed # type ignore[something] in the pytest repo.
Would it be reasonable to do a pull request that adds # type: ignore[attr-defined] to the two lines that fail the mypy hook, and to link it as a fix for this issue?

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]

I can confirm that the mypy hook passes after adding #type: ignore[attr-defined] lines at those locations.

WarrenTheRabbit added a commit to WarrenTheRabbit/pytest that referenced this issue Aug 24, 2023
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]
```
nicoddemus pushed a commit that referenced this issue Sep 9, 2023
Co-authored-by: Warren Markham <rabbitsinwarrens@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant