Skip to content

Flaky mypy error on typeshed test_cases #11220

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

Closed
hauntsaninja opened this issue Jan 2, 2024 · 7 comments · Fixed by #11343 or #11346
Closed

Flaky mypy error on typeshed test_cases #11220

hauntsaninja opened this issue Jan 2, 2024 · 7 comments · Fixed by #11343 or #11346
Labels
project: infrastructure typeshed build, test, documentation, or distribution related

Comments

@hauntsaninja
Copy link
Collaborator

I've seen this a few times recently. It goes away if you retry:

mypy --platform win32 --python-version 3.8 on the test cases for 'requests': FAILURE

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/tmps_hms0ww/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "/tmp/tmps_hms0ww/.venv/lib/python3.11/site-packages/mypy/__main__.py", line [15](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:16), in console_entry
    main()
  File "mypy/main.py", line 100, in main
  File "mypy/main.py", line [18](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:19)2, in run_build
  File "mypy/build.py", line [19](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:20)1, in build
  File "mypy/build.py", line 265, in _build
  File "mypy/build.py", line 2943, in dispatch
  File "mypy/build.py", line 3334, in process_graph
  File "mypy/build.py", line 3415, in process_fresh_modules
  File "mypy/build.py", line [21](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:22)11, in fix_cross_refs
  File "mypy/fixup.py", line 52, in fixup_module
  File "mypy/fixup.py", line 1[27](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:28), in visit_symbol_table
  File "mypy/lookup.py", line [31](https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219#step:5:32), in lookup_fully_qualified
AssertionError: Cannot find module for resource.struct_rusage

https://github.com/python/typeshed/actions/runs/7384516395/job/20087616635?pr=11219

@AlexWaygood AlexWaygood added the project: infrastructure typeshed build, test, documentation, or distribution related label Jan 2, 2024
@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 2, 2024

The traceback always seems to mention resource.struct_rusage, so I'm guessing it must be related to 3edfd90. But I have no idea:

  1. Why that commit would be causing mypy to crash
  2. Why the crash only occurs sometimes, not all the time
  3. Why the crash is only occurring in our CI on runs of regr_test.py, not on runs of mypy_test.py or stubtest_stdlib.py

@AlexWaygood
Copy link
Member

I managed to repro this locally, though I had to run python tests/regr_test.py --all 4 times in a row before I hit the AssertionError.

srittau added a commit to srittau/typeshed that referenced this issue Jan 15, 2024
They fail intermittently, see python#11220 for details.
@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Jan 16, 2024

I ran it thirty times on my Mac laptop without a repro :-/ I'll try on a Linux machine tomorrow

Assuming it's related to that commit, I almost wonder if something dumb like moving the import into the same clause would fix...

@srittau
Copy link
Collaborator

srittau commented Jan 16, 2024

I was thinking about moving the struct into its own internal module to reduce the import cycle. (Fixing mypy would be the best course of action, although that could be hard with a non-reproducible bug.)

@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 29, 2024

Hmmm... this feels like #10714 (comment)... I wonder...

Edit: no, that doesn't seem to be it. Switching to use a ProcessPoolExecutor locally doesn't fix the crash.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 30, 2024

This is the tiny script I'm using to repro the crash, FWIW. It generally occurs for me within the first three iterations:

import subprocess
import itertools
import sys

for i in itertools.count():
    print(f"Iteration {i}")
    ret = subprocess.run(
        [sys.executable, "tests/regr_test.py", "--all"],
        text=True
    )
    if ret.returncode != 0:
        break

@hauntsaninja
Copy link
Collaborator Author

Thanks for following up! Still not able to reproduce on Mac, but was able to reproduce on Linux.

hauntsaninja added a commit to hauntsaninja/typeshed that referenced this issue Jan 30, 2024
@hauntsaninja hauntsaninja reopened this Jan 30, 2024
srittau added a commit to srittau/typeshed that referenced this issue Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: infrastructure typeshed build, test, documentation, or distribution related
Projects
None yet
3 participants