Skip to content

Flaky mypy error on typeshed test_cases #11220

Description

@hauntsaninja

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

Activity

  1. AlexWaygood commented on Jan 2, 2024

    @AlexWaygood
    Member

    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
  2. AlexWaygood commented on Jan 7, 2024

    @AlexWaygood
    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.

  3. added a commit that references this issue on Jan 15, 2024
  4. hauntsaninja commented on Jan 16, 2024

    @hauntsaninja
    CollaboratorAuthor

    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...

  5. srittau commented on Jan 16, 2024

    @srittau
    Collaborator

    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.)

  6. AlexWaygood commented on Jan 29, 2024

    @AlexWaygood
    Member

    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.

  7. AlexWaygood commented on Jan 30, 2024

    @AlexWaygood
    Member

    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
  8. hauntsaninja commented on Jan 30, 2024

    @hauntsaninja
    CollaboratorAuthor

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

  9. added a commit that references this issue on Jan 30, 2024
    de01688
  10. added a commit that references this issue on Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions