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

New semantic analyzer: Refactor handling of is_inferred_def & co #6458

Open
ilevkivskyi opened this issue Feb 21, 2019 · 0 comments
Open

New semantic analyzer: Refactor handling of is_inferred_def & co #6458

ilevkivskyi opened this issue Feb 21, 2019 · 0 comments
Labels
priority-1-normal refactoring Changing mypy's internals semantic-analyzer Problems that happen during semantic analysis

Comments

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Feb 21, 2019

There are several things that hold information about whether a type of variable should be inferred or not:

  • RefExpr.is_new_def
  • RefExpr.is_inferred_def
  • Var.is_ready
  • Var.is_inferred
  • TypeChecker.is_definition()

Such a variety of things is partially caused by the fact that special definitions like named tuples etc. used to have a Var() to which the lvalue was pointing. With the new analyzer we don't have this, so it would be good to clean-up/refactor the logic around inference after we merge the two analyzers.

See also #6453

@ilevkivskyi ilevkivskyi added refactoring Changing mypy's internals priority-1-normal semantic-analyzer Problems that happen during semantic analysis labels Feb 21, 2019
ilevkivskyi added a commit that referenced this issue Jun 13, 2019
#6988)

This is (kind of) an actual fix for #6952

The problem is that previously `unwrap_final()` unconditionally set `s.type` to `None` for bare `Final`, even if the type was inferred from a simple literal r.h.s. on a previous iteration. At the same time `lvalue.is_inferred_def` remained `False`, so that the type was not inferred on the second iteration.

This way `s.type` and `lvalue.is_inferred_def` may get out of sync depending on the number of iterations, thus causing weird behavior in type checker.

I generally can say the current way of storing the inferred status is error-prone, but we already have #6458 to track this.
PattenR pushed a commit to PattenR/mypy that referenced this issue Jun 23, 2019
python#6988)

This is (kind of) an actual fix for python#6952

The problem is that previously `unwrap_final()` unconditionally set `s.type` to `None` for bare `Final`, even if the type was inferred from a simple literal r.h.s. on a previous iteration. At the same time `lvalue.is_inferred_def` remained `False`, so that the type was not inferred on the second iteration.

This way `s.type` and `lvalue.is_inferred_def` may get out of sync depending on the number of iterations, thus causing weird behavior in type checker.

I generally can say the current way of storing the inferred status is error-prone, but we already have python#6458 to track this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-normal refactoring Changing mypy's internals semantic-analyzer Problems that happen during semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant