Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-20542: Fix crash in split_for_callable when passing values to variadic generics #20543

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

Conversation

@a12k
Copy link
Contributor

@a12k a12k commented Jan 7, 2026

Fixes gh-20542

Small change, previously passing a literal value (fn[1] in the repro case) to a function using TypeVarTupleassert caused a crash in split_for_callable in checkexpr.py due to an assert statement. This PR just replaces the assertion with a proper validation check and error message.

This comment has been minimized.

This comment has been minimized.

)
return [AnyType(TypeOfAny.from_error)] * len(vars)

if not vars or not any(isinstance(v, TypeVarTupleType) for v in vars):
Copy link
Collaborator

@A5rocks A5rocks Jan 8, 2026

Choose a reason for hiding this comment

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

What happens if you add or not t.is_type_obj()? Does mypy error later? The error message you added isn't very clear IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking if we added or not t.is_type_obj() to the guard it would return more generic errors. In the test below, the return is Invalid type: try using Literal[1] instead? but with the additional guard I think it would be something like error: Type expected?, which is correct, but not as specific as it could be.

I probably should use the messagebuilder for the error though. :)

Copy link
Collaborator

@A5rocks A5rocks Jan 8, 2026

Choose a reason for hiding this comment

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

Which one is the current? Neither matches what you have ATM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! I'm sorry, I misread what line you were commenting on. You're saying why not turn if not vars or not any(isinstance(v, TypeVarTupleType) for v in vars): to if not vars or not any(isinstance(v, TypeVarTupleType) for v in vars) or not t.is_type_object().

I tried this and we produce the Type application is only supported for generic classes and Invalid type: try using Literal[1] instead? in the test against this part of the code. Looking at it, I'm thinking this is likely a lot cleaner and I would just suggest striking my current changes and changing to simply appending or not t.is_type_object() to line 4966. What do you think?

Copy link
Collaborator

@A5rocks A5rocks Jan 8, 2026

Choose a reason for hiding this comment

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

Yeah that seems like a better error output, if I'm understanding correctly.

a12k and sterliakov reacted with thumbs up emoji
Copy link
Contributor

github-actions bot commented Jan 8, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thank you!

@hauntsaninja hauntsaninja merged commit 1b8e1a8 into python:master Jan 13, 2026
23 checks passed
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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Assertion failure crash in split_for_callable: assert t.is_type_obj()

AltStyle によって変換されたページ (->オリジナル) /