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

Fix error reporting context for missing generic type arguments #7100

Merged
merged 5 commits into from
Jul 3, 2019

Conversation

ilevkivskyi
Copy link
Member

Fixes #7077

The logic of the fix is quite straightforward: emit the error immediately when we fix an instance type, and not in a traversal after the main pass. Note that I fix this only for the new analyser, because the old one will be anyway deprecated soon.

This causes a bit of code churn because we need to pass the flags to several functions, but the logic should not change much. I didn't add many new tests, since we have a bunch of existing tests. It would probably make sense to play with this, suggestions for more tests are very welcome.

@ilevkivskyi ilevkivskyi requested a review from msullivan June 28, 2019 20:10
@msullivan
Copy link
Collaborator

I wasn't able to fully test this out internally because I ran into some other issues but one thing I noticed is this makes aliases like Foo = List illegal. (Even though if you # type: ignore the error they do work correctly)

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.

This looks reasonable to me, modulo my concern about Foo = List style aliases

@@ -2369,7 +2369,9 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
# so we need to replace it with non-explicit Anys.
res = make_any_non_explicit(res)
no_args = isinstance(res, Instance) and not res.args
fix_instance_types(res, self.fail)
fix_instance_types(res, self.fail,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this needs to be done conditionally only when no_args, maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, aliases like A = List should be allowed even with the flag, will fix it now.

@ilevkivskyi
Copy link
Member Author

@msullivan I fixed the errors you reported, could you please try again?

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.

Looks great. Thanks for this.

@ilevkivskyi ilevkivskyi merged commit 3549c0e into python:master Jul 3, 2019
@ilevkivskyi ilevkivskyi deleted the newan-fix-disallow-any branch July 3, 2019 07:23
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.

--disallow-any-generics generates spurious messages
2 participants