KEMBAR78
Fix [override] error with no line number when argument node has no line number by brianschubert · Pull Request #18122 · python/mypy · GitHub
Skip to content

Conversation

brianschubert
Copy link
Member

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).

@github-actions
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!

@JukkaL JukkaL merged commit 3b00002 into python:master Nov 7, 2024
19 checks passed
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