Add future=True to all NodeNG.statement() calls#5310
Add future=True to all NodeNG.statement() calls#5310DanielNoord merged 7 commits intopylint-dev:mainfrom
future=True to all NodeNG.statement() calls#5310Conversation
Pull Request Test Coverage Report for Build 1586518271
💛 - Coveralls |
9db3e0f to
810d649
Compare
|
Opening and closing to run @Pierre-Sassoulas I put this in |
|
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
| continue | ||
| except exceptions.StatementMissing: | ||
| continue | ||
| except AttributeError: |
There was a problem hiding this comment.
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 😄
| 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.
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.
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.
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.
This is a regression test for code I found while working on this.
| ): | ||
| prev_line = node.parent.body[0].tolineno + 1 | ||
| elif isinstance(node.parent, nodes.Module): | ||
| prev_line = 0 |
There was a problem hiding this comment.
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 🎉 |
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
LGTM, just some small suggestions.
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
LGTM, but I'm going to wait for @cdce8p review to merge.
pylint/checkers/typecheck.py
Outdated
|
|
||
| import astroid | ||
| from astroid import bases, nodes | ||
| from astroid import bases, exceptions, nodes |
There was a problem hiding this comment.
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 exceptionsThus 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.
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.
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.
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.
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.
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