Skip to content

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

Conversation

onlined
Copy link
Contributor

@onlined onlined commented May 6, 2019

Fix #5806.

@@ -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]
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, fixing now.

Copy link
Member

@gvanrossum gvanrossum left a 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.

@@ -249,6 +249,8 @@ def __init__(self,
is_stub: bool,
errors: Errors) -> None:
self.class_nesting = 0
Copy link
Member

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.

Copy link
Contributor Author

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]
Copy link
Member

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'])?

@gvanrossum
Copy link
Member

Thanks! Ready to be merged once the tests pass.

@gvanrossum gvanrossum merged commit 9f823a7 into python:master May 6, 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.

No error for missing argument in type comment if function nested within method
2 participants