Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ilevkivskyi
Copy link
Member

Fixes #7044

The crash is caused by the fact that .type for broken overloads can be None. There is another example where we deal with this in analyze_ref_expr(). The crash doesn't happen on the old analyzer because it doesn't add the broken overload to the symbol table.

I solve the crash by generating a dummy Overloaded() type in this case. An alternative solution would be to re-analyze a broken overload as independent (re-)definitions, but I think this is more error-prone to keep an overload in AST, but a bunch of functions in symbol table.

Using this opportunity I also remove a redundant add_symbol() call (we always add the overload before even processing it).

Note that the behavior of the new analyzer is still different from the old one, but IMO it is more consistent in some sense.

@ilevkivskyi ilevkivskyi requested a review from JukkaL July 9, 2019 11:46
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 quick fix! Looks good, just a few comments about implementation details.

[None, None], any_type,
fallback,
line=func.line, is_ellipsis_args=True)
return Overloaded([dummy])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't we just return dummy? Add a comment explaining why.

return callable_type(func, fallback)
else:
# Broken overloads can have self.type set to None.
assert isinstance(func, mypy.nodes.OverloadedFuncDef)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be better to always set the overload type in the semantic analyzer. No need to do anything about this now, but consider adding a TODO comment.

@ilevkivskyi ilevkivskyi merged commit 438a3e9 into python:master Jul 9, 2019
@ilevkivskyi ilevkivskyi deleted the fix--newan-badover branch July 9, 2019 13:02
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.

New semantic analyzer: crash on assignment to sqlalchemy @hybrid_property

2 participants