-
-
Notifications
You must be signed in to change notification settings - Fork 274
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 doc_node attribute #1276
Add doc_node attribute #1276
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.
Thank you for this, I expected more work to be fair, this is rather elegant. As it's a "big" features I'll wait for opinion on it and it's going to be in astroid 2.10.
I haven't reviewed the code yet, but can't this be added to all nodes? VARIABLE = 1
"""A variable I will use somewhere""" IDEs know that this docstring belongs to the variable. If we're creating this new attribute we might as well try and do it for all nodes? This would allows allow us to call |
To doc_node is only used for four nodes, so does it really make sense to add it to all. Especially if |
As I said, one of the benefits would be that we can do By the way, I'm happy to assist in changing this so it is added to all |
@DanielNoord okay, the let me add it to all nodes. Which is the right class for that? |
|
done |
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.
Sorry for taking a little longer to review this!
Although this wouldn't actually add doc_node
to Const
nodes, I think it is a good start. Adding it as an attribute to NodeNG
makes sense to me anyway.
Please let me know if you have any questions! Happy to help move this along 😄
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
for more information, see https://pre-commit.ci
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.
@cdce8p Not sure if this was ready for review yet, but I thought it would be good to keep up with what you're doing so we can merge this as soon as it is done. Please dismiss if this is not ready yet.
I only have minor questions and comments though.
Could you also add a test case for return annotation in string format for a function definition? From my initial read of the code I wondered if this would be handled correctly. I tested, and it does (why would I think otherwise with one of your PR's 😅) but it would be good to have a test case as well.
@kasium Sorry for taking over your PR. You already did an awesome job 🚀 Unfortunately, this PR blocks the next pylint release. Combined with the necessary changes, I though that it would be faster to work on it myself.
It is ready now 😄
Done. Although string return annotations weren't an issue, I only accepted comments for Module docstrings. Noticed that this might be useful as I was writing the test case. It's fixed now. |
data = "\n".join(self._data[lineno - 1 : end_range]) | ||
|
||
found_start, found_end = False, False | ||
open_brackets = 0 | ||
skip_token: set[int] = {token.NEWLINE, token.INDENT} | ||
skip_token: Set[int] = {token.NEWLINE, token.INDENT} |
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 actually saw this during review and thought I had learned something new from you (set
being able to used on < 3.8/9) but alas... 😄
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.
It can actually be used be used in 3.7 and 3.8 (with from __future__ import annotations
), but not in 3.6.
Really time to remove support for 3.6 soon.
Technically, you could use "set[int]"
(note the quotation marks) in 3.6, but that isn't really worth 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, I have been looking forward to seeing you use your typing updater tool 😄
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 we don't need a test for the order issue as it will be found in #1411
Sounds good! Have you been able to test the pylint issue? Will this PR resolve it? |
Not tested, but I'm fairly positive it should. See my comment in #1411. If those tests pass Edit: |
I'll do one last check against Home Assistant, just to make sure and merge it afterwards. That way we can both still work on the two followups today and hopefully have the release ready tomorrow. Around ~10min. |
@cdce8p Sounds good to me! Ping me when you need me 😄 My PR is ready. You can review it if you want. It's just a bunch of tests now. |
Thanks for finishing it! |
Steps
Description
This change adds a new attribute
doc_node
toClassDef
,FunctionDef
,AsyncFunctionDef
andModule
. This is needed, since some checks in pylint not only need the docstring as a string, but the node containing it. For details see pylint-dev/pylint#3077Type of Changes
Related Issue
pylint-dev/pylint#3077