-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Stable API for all node name #1811
Comments
I looked at I think it could make sense, but on the other hand: how often would this save an def func(node: nodes.NodeNG):
if isinstance(node, nodes.Name):
name = node.name
elif isinstance(node, nodes.Attribute):
name = node.attrname
else:
# do something for other types. How often do we have a situation where a def func(node: nodes.NodeNG):
if isinstance(node, (nodes.Name, nodes.Attribute)):
if isinstance(node, nodes.Attribute):
name = node.attrname
else:
name = node.name
else:
# do something for other types. I'm not sure that happens often? If this allows many simplifications I would support it, if it's easier to just refactor some |
What about an API requirement that every kind of node has an
so no need to do |
What would be the |
Good point. I can see those two don't have something like a name attribute. One option would be to
to stick to the API as an initial iteration. |
That doesn't really make a lot of sense and would only be necessary to make them conform to an API. As we're still able to design that API we shouldn't introduce such weird edge cases into it. |
I'm under the impression we had multiple crash in release because of that (especially since we want to make better error message). We can also remember that everything that is a variable can be a class attribute too and ask for more functional test during review in pylint. But the cost of forgetting is a crash, so "fixing it" in astroid directly might make sense. |
There are some: But with correct typing and a |
Closing in favor of #1287 |
Current behavior
We often have the following code in pylint:
This is the reason for a lot of crashes too.
Expected behavior
Maybe it would be a good thing to have a
name
attribute that return attrname if required ? (I don't think if we have nodes who have both name and attrname.)The text was updated successfully, but these errors were encountered: