-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Don't add self argument if nested function in method #6769
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
Don't add self argument if nested function in method #6769
Conversation
mypy/fastparse.py
Outdated
@@ -513,6 +516,7 @@ def do_func_def(self, n: Union[ast3.FunctionDef, ast3.AsyncFunctionDef], | |||
func_type.definition = func_def | |||
func_type.line = lineno | |||
|
|||
retval: Union[FuncDef, Decorator] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because mypy needs to run with Python 3.5, you can't use this PEP-526 syntax here yet (which is 3.6 or later only). To fix this, use a type comment on the first line that assigns to retval
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixing now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm basically happy with this -- one nit and a suggestion for an extra test.
mypy/fastparse.py
Outdated
@@ -249,6 +249,8 @@ def __init__(self, | |||
is_stub: bool, | |||
errors: Errors) -> None: | |||
self.class_nesting = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you delete this variable? It's no longer updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I forgot it.
@@ -737,6 +737,14 @@ class A: | |||
main:6: error: Incompatible types in assignment (expression has type "int", variable has type "A") | |||
main:8: error: Argument 1 to "g" has incompatible type "A"; expected "int" | |||
|
|||
[case testNestedFunctionInMethodWithTooFewArgumentsInTypeComment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could also add a test for a few other configurations of the stack, e.g. a method inside a class inside a method (i.e. ['C', 'F', 'C', 'F']
)?
Thanks! Ready to be merged once the tests pass. |
Fix #5806.