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

Point incompatible override error to argument rather than method header #8408

Closed
wants to merge 1 commit into from
Closed

Conversation

dhalenok
Copy link
Contributor

Possibly closes #8298.

@dhalenok dhalenok requested a review from JukkaL February 15, 2020 19:54
@dhalenok
Copy link
Contributor Author

@JukkaL

While I was working on #8298, I've stumbled upon a different issue: arguments always had the same line as the FuncDef.

I've tracked it down to this method in FuncItem:

mypy/mypy/nodes.py

Lines 627 to 633 in 83012da

def set_line(self,
target: Union[Context, int],
column: Optional[int] = None,
end_line: Optional[int] = None) -> None:
super().set_line(target, column, end_line)
for arg in self.arguments:
arg.set_line(self.line, self.column, self.end_line)

Which gets called while parsing FuncDef:

func_def.set_line(lineno, n.col_offset, end_lineno)

This was basically always overwriting arg's line.

However, removing

mypy/mypy/nodes.py

Lines 632 to 633 in 83012da

for arg in self.arguments:
arg.set_line(self.line, self.column, self.end_line)

didn't completely solve the problem. At this point, the argument's line was always -1.
I've modified make_argument (in fastparse.py) by creating the argument variable and calling set_line on it before returning it.

@@ -1643,14 +1643,15 @@ def erase_override(t: Type) -> Type:
if not is_subtype(original.arg_types[i],
erase_override(override.arg_types[i])):
arg_type_in_super = original.arg_types[i]
arg_node = override.definition.arguments[i+1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem quite right. It seems that you are passing this to forward the correct context, but 1) you are passing the next argument as context? 2) arguments aren't contexts. You probably want to make sure the context is set correctly to begin with.

@97littleleaf11
Copy link
Collaborator

Thanks for your PR! But I'm going to close it due to inactive status. Feel free to reopen it if you still work on this!

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.

Better error location for incompatible override due to argument incompatibility
3 participants