-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 future=True
to all NodeNG.statement()
calls
#5310
Conversation
Pull Request Test Coverage Report for Build 1586518271
π - Coveralls |
9db3e0f
to
810d649
Compare
Opening and closing to run @Pierre-Sassoulas I put this in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π
primers bringing value again π |
Moving to 2.13 because of the test fail (could be 2.12.x too). |
Looking into crash as we speak! |
Blocked by #5382. |
a92e5dc
to
74bda43
Compare
77c959e
to
0bd10b0
Compare
]: | ||
missingattr.add((owner, name)) | ||
continue | ||
except exceptions.StatementMissing: | ||
continue | ||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also catching another AttributeError
besides the missing parent
attribute that is now captured in exceptions.StatementMissing
. Thanks to the primer for finding this potential crash before committing to main
π
@@ -1890,29 +1889,36 @@ def _loopvar_name(self, node: astroid.Name) -> None: | |||
# the variable is not defined. | |||
scope = node.scope() | |||
if isinstance(scope, nodes.FunctionDef) and any( | |||
asmt.statement().parent_of(scope) for asmt in astmts | |||
asmt.scope().parent_of(scope) for asmt in astmts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to check if the scope of asmt
is the parent scope of node
's scope. Previously this relied on nodes.Module.statement()
returning itself. Using scope
seems to be more sensical here.
astmts[0].is_statement | ||
or not isinstance(astmts[0].parent, nodes.Module) | ||
and astmts[0].statement(future=True).parent_of(node) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was particularly trigger to get right, but this is testing what we want. If parent
is the root Module
and the parent of node
we don't do _astmts = astmts[:1]
. The other or
is simply what we did previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I think you know more about this particular method than I do. It looks like it could work π
|
||
|
||
else: | ||
ellipsis = type(Ellipsis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression test for code I found while working on this.
@@ -602,8 +602,10 @@ def visit_default(self, node: nodes.NodeNG) -> None: | |||
isinstance(node.parent, nodes.TryFinally) and node in node.parent.finalbody | |||
): | |||
prev_line = node.parent.body[0].tolineno + 1 | |||
elif isinstance(node.parent, nodes.Module): | |||
prev_line = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same effect as doing node.parent.fromlineno
but avoids the StatementMissing
exception from calling statement
.
@cdce8p This is finally ready for review π |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some small suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'm going to wait for @cdce8p review to merge.
pylint/checkers/typecheck.py
Outdated
@@ -72,7 +72,7 @@ | |||
from typing import Any, Callable, Iterator, List, Optional, Pattern, Tuple | |||
|
|||
import astroid | |||
from astroid import bases, nodes | |||
from astroid import bases, exceptions, nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should use this import here.
There is a pylint.exceptions
package too which is often imported with
from pylint import exceptions
Thus doing the same for astroid will lead to name conflicts.
At some point @Pierre-Sassoulas and I discussed this I think, although we didn't reach a conclusion for a good name. For the time being, I would recommend this
import astroid.exceptions
try:
...
except astroid.exceptions...:
...
It's a bit lengthy but already used elsewhere. Should be good enough util we find something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added an import astroid.exceptions
line. There is already a import astroid
statement, but astroid.exceptions.StatementMissing
could not be resolved by VS Code (/ Pylance).. I think because of the wildcard import in __init__.py
in astroid
.
pylint/checkers/typecheck.py
Outdated
except exceptions.StatementMissing: | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the discussion about not adding the FrameMissing
error in astroid, I've been thinking if we should deprecate / remove the StatementMissing
error, too.
Is there a benefit here with it being more specific? I would probably recommend to just catch ParentMissingError
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there is any benefit, perhaps when doing something like [(i.frame(), j.statement()) for i,j in zip(nodes, other_nodes)]
but that is really really convoluted...
On the other hand, we have already gone to the effort of adding it and I don't think it adds too much boilerplate to the astroid
codebase. We never know when we might need it in the future so I'd say let's just keep it in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's keep it. Only because it's already in astroid
π
astmts[0].is_statement | ||
or not isinstance(astmts[0].parent, nodes.Module) | ||
and astmts[0].statement(future=True).parent_of(node) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I think you know more about this particular method than I do. It looks like it could work π
Type of Changes
Description
Ref pylint-dev/astroid#1235