-
-
Notifications
You must be signed in to change notification settings - Fork 275
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 position
attribute for nodes
#1393
Conversation
4fd12d9
to
4c4e14c
Compare
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, the tests in particular look great.
if PY36: | ||
# In Python 3.6, the token type for 'async' was 'ASYNC' | ||
# In Python 3.7, the type was changed to 'NAME' and 'ASYNC' removed | ||
# Python 3.8 added it back. However, if we use it unconditionally | ||
# we would break 3.7. | ||
keyword_tokens = (token.NAME, token.ASYNC) |
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're going to remove python 3.6 support in 2.11, I guess we'll just have to remove that part when we actually do it ?
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.
Yeah. For a moment I thought about just ignoring the error in Python 3.6. Then again, that would be cheating. In the end, when updating we're gonna search for PY36
anyway. It's also trivial to update.
@@ -0,0 +1,10 @@ | |||
from typing import NamedTuple |
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.
Great utility class !
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.
Looks very good @cdce8p
One day I'll write such good first-try PRs as well 😄
astroid/rebuilder.py
Outdated
else: | ||
return None | ||
|
||
start_token = cast(TokenInfo, start_token) # type: ignore[redundant-cast] # necessary for pyright |
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.
Is this a false positive? Or will mypy
also require this in the future?
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.
One of the rare instances where mypy
is smarter than pyright
. I'll probably report that error soon. So might as well remove it now.
class D: #@ | ||
... | ||
|
||
class E: #@ |
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.
Shall we add one test with a decorator? I tested and it works fine currently, but it might be good to have it in there as well.
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.
3aad465
to
2f117d2
Compare
Some last open questions
|
I think
What about
Shall we add a todo and do so in
I think it makes sense to do so. The change is significant and we would likely forget about it later on. At |
At first I was thinking that we could use it in pylint too. I think it's possible but this is one more thing to keep track off and would increase the coupling between pylint and astroid so I did not suggest it. Also increasing what we consider the astroid's API is also increasing the chance of having to deal with breaking changes later.
I think it's safe to do, especially considering that pycodestyle also does it. |
@Pierre-Sassoulas I see you requested a review, but there are some open questions from @cdce8p that still need to be solved. @cdce8p Do you know if you'll have the time to look into this this week? If not, I could offer some help? I really think we should try and land this and then release |
@DanielNoord I looked at a few PRs today tagged for Once Some things to keep in mind
|
Personally I'd really like to land #1306 as it is blocking some work I'd like to do on There is also the
Yes I will.
I'm going to add if position:
...
elif node.position:
...
elif node.lineno:
...
elif ...:
... That would work right?
Yeah I'll do a quick inspection in VSC. Test updating should be easy. |
👌🏻 The
Not sure if that would actually be used. Usually errors are bound to node. No harm in adding
Thanks! |
Description
Supersedes #1390
Ref pylint-dev/pylint#5466
Opened a new PR to preserve the original idea and discussion.
This PR adds the new (optional) attribute
position
toNodeNG
. It should be used to highlight the position / range of keyword(s) and name for block nodes such asClassDef
andFunctionDef
where the AST nodes don't include good enough positional information.Additional block nodes for which it could make sense include
Match
,MatchCase
,ExceptHandler
, (and laterWithItem
). To a limited extend,If
,For
, andWhile
might also work.Type of Changes