GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `class S(tuple[*tuple[()]])` crashes mypy · Issue #19105 · python/mypy

class S(tuple[*tuple[()]]) crashes mypy #19105

New issue
Copy link
New issue
Copy link
Closed
#19111
Closed
class S(tuple[*tuple[()]]) crashes mypy#19105
#19111
Copy link
Labels
crashtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

Description

@jorenham
jorenham
opened on May 18, 2025
Issue body actions
class S(tuple[*tuple[()]]): ...

mypy 1.15 stacktrace (mypy-play):

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 119, in main
  File "mypy/main.py", line 203, in run_build
  File "mypy/build.py", line 191, in build
  File "mypy/build.py", line 267, in _build
  File "mypy/build.py", line 2937, in dispatch
  File "mypy/build.py", line 3335, in process_graph
  File "mypy/build.py", line 3430, in process_stale_scc
  File "mypy/semanal_main.py", line 97, in semantic_analysis_for_scc
  File "mypy/semanal.py", line 7621, in apply_semantic_analyzer_patches
  File "mypy/semanal.py", line 2587, in <lambda>
  File "mypy/semanal_shared.py", line 305, in calculate_tuple_fallback
NotImplementedError

and on current master (mypy-play)

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "mypy/__main__.py", line 37, in <module>
    console_entry()
  File "mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 127, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/main.py", line 211, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/build.py", line 191, in build
    result = _build(
             ^^^^^^^
  File "mypy/build.py", line 267, in _build
    graph = dispatch(sources, manager, stdout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/build.py", line 2939, in dispatch
    process_graph(graph, manager)
  File "mypy/build.py", line 3337, in process_graph
    process_stale_scc(graph, scc, manager)
  File "mypy/build.py", line 3432, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "mypy/semanal_main.py", line 99, in semantic_analysis_for_scc
    apply_semantic_analyzer_patches(patches)
  File "mypy/semanal.py", line 7740, in apply_semantic_analyzer_patches
    patch_func()
  File "mypy/semanal.py", line 2630, in <lambda>
    self.schedule_patch(PRIORITY_FALLBACKS, lambda: calculate_tuple_fallback(base))
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/semanal_shared.py", line 305, in calculate_tuple_fallback
    raise NotImplementedError

another way to trigger this crash is through a typo in the variadic type parameter name:

class MyTuple[*Ts](tuple[*_Ts]): ...  # oh no a typo

this produces an identical stacktrace (mypy-play)


some observations:

  • it doesn't matter if typing.Unpack is used instead of *
  • I checked all versions from 1.9.0-master, and all crash in the same way
  • class S(tuple[()]): ... does not cause a crash
    (although S() is revealed as tuple[(), fallback=__main__.S], which is kinda sus)
  • in case you didn't notice; the first example is valid at runtime, the second isn't
  • my ear is a bit itchy

And it's probably not what you want to hear, but it might be relevant info, so I'll carefully whisper it: Pyright does not have this problem (playground 1, playground 2), and the same goes for ty (playground 1, playground 2)


ref: #19100 (comment)

Activity

  1. jorenham
    added
    crash
    on May 18, 2025
  2. jorenham
    changed the title [-]`class S(tuple[*tuple[()]]): ...` crashes mypy[/-] [+]`class S(tuple[*tuple[()]])` crashes mypy[/+] on May 18, 2025
  3. sterliakov commented on May 19, 2025

    @sterliakov
    sterliakov
    on May 19, 2025
    Collaborator
    More actions

    Ough, note this isn't specific to empty tuples, the following crashes just as hard:

    class S(tuple[*tuple[int]]): ...
    Reacted by Joren Hammudoglu
  4. sterliakov commented on May 19, 2025

    @sterliakov
    sterliakov
    on May 19, 2025
    Collaborator
    More actions

    Quick braindump: we normalize such trivial tuples in semanal_typeargs, but TypeArgumentsAnalyzer runs after we have calculated all fallbacks. Fallback calculation logic assumes normalized inputs, which is most probably wrong. I'm not sure whether what I did is the best approach, but at least it doesn't crash anymore - let's continue this discussion in the linked PR.

    Reacted by Joren Hammudoglu
  5. sterliakov
    added
    topic-pep-646PEP 646 (TypeVarTuple, Unpack)
    on May 19, 2025
  6. sterliakov
    added a commit that references this issue on Jul 4, 2025

    Merge remote-tracking branch 'upstream/master' into bugfix/pythongh-1…

    3989212
  7. sterliakov
    added a commit that references this issue on Jul 21, 2025

    Merge branch 'master' into bugfix/pythongh-19105-trivial-unpack-in-ba…

    03a0a5b
  8. ilevkivskyi
    closed this as completedin #19111on Jul 22, 2025
  9. ilevkivskyi
    added a commit that references this issue on Jul 22, 2025

    Use normalized tuples for fallback calculation (#19111)

    This issue will close once commit 2e5d7ee is merged into the 'master' branch.
    2e5d7ee
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

    crashtopic-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.