Skip to content
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

Fix [override] error with no line number when argument node has no line number #18122

Merged

Conversation

brianschubert
Copy link
Collaborator

Refs #18115

When a parameter type in a method override is incompatible with the parameter type in the supertype definition, mypy emits an error using the Argument node as the context.

However, sometimes the the Argument node doesn't have a line number set, causing the error message to have no associated line number. This happens with the __replace__ methods created in the dataclass plugin, which have line numbers set on the FuncDef nodes, but no line numbers set on the individual argument nodes.

This PR fixes the missing line number in the error by falling-back to the FuncDef line number when a line number isn't set on the Argument node.

(As an alternative fix, we could add line numbers to the Argument nodes in the dataclass plugin, but that looks like a more complicated change since multiple methods would be affected).

Copy link
Contributor

github-actions bot commented Nov 7, 2024

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

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

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.

2 participants