-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 node_ancestors method #1169
Conversation
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 think it's useful to add ancestors
in the NodeNG API, I'm pretty sure I've seen it done in pylint but the logical place seems to be 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.
This will be a great helper method! Thanks for working on it.
I only did a quick search in pylint/checkers/utils.py
and already found a few places where it would be useful.
There should also be a |
f4ccfda
to
0305013
Compare
I've been thinking about ways to get rid of unbounded `while` loops in the Pylint codebase. A common use is to loop over a node's ancestors. The `node_ancestors` method centralizes this logic in one place so that those `while` loops can be rewritten as `for`. A few uses are made of this new method. It only comes up a few places in Astroid, but there are many more in Pylint.
0305013
to
776004d
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.
Looks good!
As explained earlier, with the name conflict I would just leave it at node_ancestors
.
--
@nickdrozd Just a small note. Could you please not force-push any new changes in future PRs? That will make reviewing them more difficult. In the end we can always squash merge them.
I've been thinking about ways to get rid of unbounded
while
loops inthe Pylint codebase. A common use is to loop over a node's ancestors.
The
node_ancestors
method centralizes this logic in one place sothat those
while
loops can be rewritten asfor
.A few uses are made of this new method. It only comes up a few places
in Astroid, but there are many more in Pylint.
Type of Changes