-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add stronger typing to nodes.py #1783
Labels
Comments
This would be good. I've thought about a similar thing myself. |
rwbarton
added a commit
to rwbarton/mypy
that referenced
this issue
Jul 1, 2016
This doesn't actually do anything yet, as Statement and Expression are just synonyms for Node. But it's part of the work that will need to be done for python#1783, and for now it serves as (unchecked) documentation.
rwbarton
added a commit
to rwbarton/mypy
that referenced
this issue
Jul 1, 2016
This doesn't actually do anything yet, as Statement and Expression are just synonyms for Node. But it's part of the work that will need to be done for python#1783, and for now it serves as (unchecked) documentation.
gvanrossum
pushed a commit
that referenced
this issue
Jul 1, 2016
This doesn't actually do anything yet, as Statement and Expression are just synonyms for Node. But it's part of the work that will need to be done for #1783, and for now it serves as (unchecked) documentation.
This was referenced Sep 12, 2016
This was referenced Oct 1, 2016
gvanrossum
pushed a commit
that referenced
this issue
Oct 3, 2016
For me this is ongoing, but it is more subtle. So I'd say close. Some day we'll have patterns (lvalues) and stuff. |
The second and third paragraphs aren't done yet AFAIK. |
We need an ExpressionVisitor. |
We have expression visitor now. Are there any additional action items here? |
I'm happy to close issues that vaguely suggest refactorings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We should have a subclass
Expression
ofNode
, make all the*Expr
node types inherit from it, and make all the fields ofNode
s that are intended to be expressions intoExpression
s. Similarly forStatement
, and possiblyVar
and related types.NodeVisitor
should be parameterized on at least two types, namely the return type on expressions and the return type on other things (mostly statements).Node
'saccept
method should be moved intoExpression
andStatement
(etc.), returning different type parameters of theNodeVisitor
. ThenTypeChecker
can become aNodeVisitor[Type, None]
, meaning that it returns a type on an expression but returns nothing on a statement.Then
TypeChecker
'svisit_*_stmt
methods wouldn't all be returningNone
where aType
was expected. So this is pretty important for getting mypy to type check itself under strict optional checking, which was my original motivation, but I think this refactoring is a good idea anyways: more specific types for the fields ofNode
subtypes give more information about what values are actually legal, which is helpful when either producing or consuming those nodes.I don't want to do this refactoring right now as it's fairly large, and the parser is one of the things heavily affected, and we currently have two of those. Better to wait until after the old parser is gone.
The text was updated successfully, but these errors were encountered: