Skip to content

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.

@github-actions

This comment has been minimized.

@github-actions

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

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

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

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.

@github-actions
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. ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants