Skip to content

Use type context from previous definition when renaming #6231

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

Open
JukkaL opened this issue Jan 21, 2019 · 0 comments
Open

Use type context from previous definition when renaming #6231

JukkaL opened this issue Jan 21, 2019 · 0 comments
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 21, 2019

Maybe we code like this shouldn't generate an error when using --allow-redefinition:

x: List[int] = []
# do something with x
x = []  # Error: need annotation

The reason for the error is that the second assignment creates a completely independent variable, so the type of the original definition has no effect.

There are still some open issues:

  • Using the context can generate false positives, in case the correct type would be something different for the second definition. I don't know how often this would be an issue.
  • Propagating the type context is somewhat tricky since the name of the previous definition is not trivial to calculate. The rules for renaming depend on the scope (local/class/global).
  • If/when we support more general redefinitions (not just within a single block), it may be unclear when we should propagate context. It may be best to first to make redefinitions more general and then reconsider this issue.

Follow-up to #6197.

@JukkaL JukkaL added needs discussion priority-1-normal false-positive mypy gave an error on correct code labels Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant