KEMBAR78
Invoke get_dynamic_class_hook on method calls by mkurnikov · Pull Request #7704 · python/mypy · GitHub
Skip to content

Conversation

@mkurnikov
Copy link
Contributor

Fixes #7266

Copy link
Member

@ilevkivskyi ilevkivskyi 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 PR! Generally looks good, I have few comments/suggestions below.

# check if method call
if isinstance(call.callee, MemberExpr):
callee_expr = call.callee.expr
if isinstance(callee_expr, NameExpr) and callee_expr.fullname:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if isinstance(callee_expr, NameExpr) and callee_expr.fullname:
if isinstance(callee_expr, RefExpr) and callee_expr.fullname:

fname = callee_expr.fullname + '.' + method_name
# else check if function call
elif isinstance(call.callee, RefExpr):
fname = call.callee.fullname
Copy link
Member

Choose a reason for hiding this comment

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

I believe the order is wrong here: a RefExpr (including MemberExpr) with a non-None full name should always take precedence.

MyManager = Manager.from_queryset(QuerySet)

reveal_type(MyManager()) # N: Revealed type is '__main__.MyManager'
reveal_type(MyManager().attr) # N: Revealed type is 'builtins.str'
Copy link
Member

Choose a reason for hiding this comment

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

Please add a check here that MyManager can be used as an annotation for a function argument.

Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Marking with "Request changes" for tracking purposes

@ilevkivskyi
Copy link
Member

@mkurnikov Note a competing PR appeared #7990, will you have time to update your PR soon?

@mkurnikov mkurnikov closed this Nov 21, 2019
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.

get_dynamic_class_hook for method calls

3 participants