Skip to content

extract_node() skips doc_node #2675

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

Open
offbynull opened this issue Feb 1, 2025 · 4 comments
Open

extract_node() skips doc_node #2675

offbynull opened this issue Feb 1, 2025 · 4 comments

Comments

@offbynull
Copy link

If you place a #@ marker on a line that's a ClassDef's docstring node, extract_node() doesn't seem to pick it out. When debugging, I noticed that the line number was properly being extracted, but doc_node wasn't being included in the children being searched for that line number. I worked around this by placing #@ on the ClassDef itself, and then manually extracting the doc_node.

The version of astroid was whatever pylint v3.3.4 pulls in.

@DanielNoord
Copy link
Collaborator

I think this is intended? The doc_node is a phantom node that doesn't really exists in the AST like the normal nodes. It makes sense to have to extract the parent node?

@offbynull
Copy link
Author

offbynull commented Feb 3, 2025 via email

@DanielNoord
Copy link
Collaborator

Perhaps, that might indeed be a nicer API.

We can probably also change it to also find the doc_node. astroid sometimes diverts from the behaviour that seems sensible from a stdlib.ast perspective as it is really tuned towards the needs of pylint. I think that is also what happened in this case.

@offbynull
Copy link
Author

offbynull commented Feb 3, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants