8000 [WIP] Tighten Lvalues and remove all references to Node by elazarg · Pull Request #2221 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Tighten Lvalues and remove all references to Node #2221

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

Closed
wants to merge 14 commits into from

Conversation

elazarg
Copy link
Contributor
@elazarg elazarg commented Oct 5, 2016

TypeMap is tighten to Dict[Expression, Type], which will help removing most of the remaining references to Node. It will also allow moving literal and literal_hash from Node to Expression (leaving only line and column as data in Node), possibly making it easier to perform the NB regarding TypeMap (see inside).

One culprit is that TypeMap is Optional everywhere now. Admittedly I don't understand why is it Optional at all.

[I intend to use this PR as a reference for changes in much smaller chunks]

All references to Node are removed from everywhere except mypy.node.

Make Lvalue a separate Union type. This has many implications; I think the PR can serve as a demonstration for now.

The need for dedicated LvalueTuple and LvalueStar is seen through the casts needed when accessing their elements. Perhaps making them generic can help.

8000
This change prepares the ground for making it Dict[Expression, Type] instead of Dict[Node, Type].

TypeMap has been moved to mypy.types, following existing dependencies in code that uses it.
@elazarg elazarg closed this Oct 5, 2016
@elazarg elazarg reopened this Oct 5, 2016
@elazarg elazarg changed the title Extract TypeMap to mypy.types Extract TypeMap and tighten (some) Lvalues Oct 5, 2016
@elazarg elazarg changed the title Extract TypeMap and tighten (some) Lvalues [WIP] Extract TypeMap to mypy.types Oct 5, 2016
@elazarg elazarg changed the title [WIP] Extract TypeMap to mypy.types [WIP] Extract TypeMap and tighten (some) Lvalues Oct 5, 2016
@rwbarton
Copy link
Contributor
rwbarton commented Oct 6, 2016

Sorry the name is bad, but TypeMap isn't just supposed to be a generic map from expressions to types, but is specifically a thing returned by find_isinstance_check that represents the knowledge about types we gain from knowing a certain expression is true (or false). It can be None when that case is impossible (e.g., an unreachable branch). There's a big comment explaining this before its definition.

I haven't been following what you've been doing here closely, but I think it doesn't make sense to merge TypeMap with other places you see Dict[Node, Type]. It's probably better to just change both TypeMap and other Dict[Node, Type]s to Dict[Expression, Type] and change as little else as possible.

@elazarg
Copy link
Contributor Author
elazarg commented Oct 6, 2016

Thanks @rwbarton. I have noticed (after posting this PR) that there are different maps with different purposes. I still think there should be a single name for each purpose, but I am not that certain.

@elazarg elazarg changed the title [WIP] Extract TypeMap and tighten (some) Lvalues [WIP] Tighten Lvalues Oct 6, 2016

class Frame(Dict[Any, Type]):
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand why is it needed. This can be fixed regardless of this PR.

type = node.node.type
def get_declaration(self, expr: BLval) -> Type:
if isinstance(expr, (RefExpr, SymbolTableNode)) and isinstance(expr.node, Var):
type = expr.node.type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test here is never true, and I think the original (changed in one of my previous PRs) was never true either. I wonder why.

@@ -1812,7 +1820,7 @@ def visit_decorator(self, e: Decorator) -> Type:
if d.fullname == 'typing.no_type_check':
e.var.type = AnyType()
e.var.is_ready = True
return NoneTyp()
return None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This mistake can be fixed regardless of this PR.

@elazarg elazarg mentioned this pull request Oct 6, 2016
@elazarg elazarg changed the title [WIP] Tighten Lvalues [WIP] Tighten Lvalues and remove all references to Node Oct 6, 2016
@gvanrossum
Copy link
Member

Will you let us know when you're ready for a review?

@elazarg
Copy link
Contributor Author
elazarg commented Oct 6, 2016

@gvanrossum this PR is ready now, as far as I'm concerned. However, since it is so big, and since introducing Lvalue as a separate type has implications on the old parser, I am splitting it to smaller chunks, without "real" Lvalue yet. I will close this one and will submit a new PR momentarily.

I also have certain questions about the specific details of the code, and about design decisions, but I don't know what's the right place to ask them; they are probably too minor for dedicated issues.

@elazarg elazarg closed this Oct 6, 2016
@elazarg elazarg deleted the extract_typemap branch October 27, 2016 15:03
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.

3 participants
0