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 — Include tuple fallback in constraints built from tuple types by sterliakov · Pull Request #19100 · python/mypy

Conversation

@sterliakov

@sterliakov sterliakov commented May 17, 2025

Copy link
Copy Markdown
Collaborator

Fixes #19093.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jorenham reacted with rocket emoji
All reactions
  • 🚀 1 reaction
sterliakov added 2 commits May 17, 2025 03:54
@sterliakov
Include fallback in building constraints for tuple types
59f8e25
@sterliakov
Add a testcase
8b23cf0
@github-actions

This comment has been minimized.

Sign in to view
A5rocks
A5rocks reviewed May 17, 2025
View reviewed changes

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. I think NamedTuples also use partial_fallback so can you add a test case using that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jorenham

jorenham commented May 18, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

will this also stop mypy from crashing in case of a typo like this?

class MyTuple[*Ts](tuple[*_Ts]): ...  # oh no a typo
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

https://mypy-play.net/?mypy=1.15.0&python=3.13&gist=1b2a9f33efc227902750f06f5b9c54e4

or should I open a new issue for this?


edit:

the same crash also seems to happen in case of valid code, btw:

class Shape0(tuple[*tuple[()]]): ...

https://mypy-play.net/?mypy=latest&python=3.13&gist=e201c77b05e55f03d4b475342475dd83

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jorenham

jorenham commented May 18, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

And similarly, how about this one:

class Shape[*Ts](tuple[*Ts]): ...

reveal_type((42, ))         # tuple[Literal[42]?]
reveal_type(Shape((42, )))  # __main__.Shape[Unpack[builtins.tuple[Never, ...]]]

https://mypy-play.net/?mypy=1.15.0&python=3.13&gist=2e2ba990a2112c97ca8d9d071c559a56

is this also covered by this fix, or a different issue?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sterliakov

sterliakov commented May 18, 2025

Copy link
Copy Markdown
Collaborator Author

@jorenham No, this will definitely not fix a crash, and I highly recommend reporting that one separately ASAP as a crash (not a bug). I'll try to look into it when I have some time - that should be an easy fix.

The second snippet is also a different issue (probably unrelated to both this PR and the crash, please report too).

@A5rocks namedtuples are handled by a different branch and we should (hopefully) already have tests for that; constraints for namedtuples are built as if they were just their fallbacks, ignoring tuple items.

Any ideas what's that xarray primer hit? I saw it on several recent PRs (cf. #19102 that definitely cannot impact type inference), so probably not related to this change, but that's still curious.

jorenham reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

A5rocks
A5rocks approved these changes May 18, 2025
View reviewed changes
This was referenced May 18, 2025
class S(tuple[*tuple[()]]) crashes mypy #19105
Closed
incorrect inference of user-defined variadic tuple subtype instances #19106
Closed
Empty variadic tuple subtype not assignable to tuple[int, ...] #19110
Closed
@sterliakov
Merge branch 'master' into bugfix/pythongh-19093-infer-constraints-in…
0fdd0bc
…clude-fallback
@github-actions

github-actions Bot commented May 29, 2025

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/__init__.py:1330: error: Unused "type: ignore" comment  [unused-ignore]
+ bson/__init__.py:1376: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hauntsaninja
hauntsaninja approved these changes Jun 18, 2025
View reviewed changes
@hauntsaninja
hauntsaninja merged commit 4cda52d into python:master Jun 18, 2025
@hauntsaninja

hauntsaninja commented Jun 18, 2025

Copy link
Copy Markdown
Collaborator

Nice!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja approved these changes
+1 more reviewer
@A5rocks A5rocks A5rocks approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Argument 1 to type_check_only has incompatible type type[S[T, *Ts]]; expected type[S[T, *Ts]]

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@sterliakov @jorenham @hauntsaninja @A5rocks
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.