-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Docstring description multiline parsing #476
base: master
Are you sure you want to change the base?
Docstring description multiline parsing #476
Conversation
Sorry I was slacking off a bit :P I have found another issue with the code (a new possible test case). When I use Ex: if I had something like this:
it would print out:
The problem is with When I made this change I noticed that around line 408/417 within
Here we are appending only I decided to convert the check into a function and call them in both places when the line is not an arg. Added 3 more tests regarding the |
Ack. That all sounds good. Will update you when I get to the review.
…On Sat, Jan 13, 2024 at 9:57 PM Mishahal Palakuniyil < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In fire/docstrings.py
<#476 (comment)>:
> @@ -410,6 +419,83 @@ def _consume_google_args_line(line_info, state):
else:
if state.current_arg:
state.current_arg.description.lines.append(split_line[0])
+ state.max_line_length = max(state.max_line_length, len(line_info.line))
+ if line_info.previous.line == state.line1: # check for line2
I have added the index as you guided and updated the code to compare
indexes instead of strings. Please review the most recent commit.
—
Reply to this email directly, view it on GitHub
<#476 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGZ6XKTW2ZEX7I5P7DXH4TYONCTHAVCNFSM6AAAAABBAQ6XUKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQMRQGEZTKOBUGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
What I mentioned might be another bug. I also just thought about this; I was messing around adding I haven't tested this, but if we add On the top of my head, I'm thinking we can do something like compare the previous line if |
def test_google_format_long_arg_long_description(self): | ||
docstring = """This is a Google-style docstring with long args. | ||
|
||
Args: | ||
function_maker_handler_event_factory: The function-maker-handler event factory | ||
responsible for making the function-maker-handler event. Use this whenever | ||
you need a function-maker-handler event made for you programmatically. | ||
""" | ||
docstring_info = docstrings.parse(docstring) | ||
expected_docstring_info = DocstringInfo( | ||
summary='This is a Google-style docstring with long args.', | ||
args=[ | ||
ArgInfo(name='function_maker_handler_event_factory', | ||
description='The function-maker-handler event factory ' | ||
'responsible for making the function-maker-handler event. ' | ||
'Use this whenever\nyou need a function-maker-handler event' | ||
' made for you programmatically.'), | ||
], | ||
) |
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 may be good to add an example here, or below, which contains a second line in the documentation before the args (since this is very common). e.g.
def test_google_format_long_arg_long_description(self): | |
docstring = """This is a Google-style docstring with long args. | |
Args: | |
function_maker_handler_event_factory: The function-maker-handler event factory | |
responsible for making the function-maker-handler event. Use this whenever | |
you need a function-maker-handler event made for you programmatically. | |
""" | |
docstring_info = docstrings.parse(docstring) | |
expected_docstring_info = DocstringInfo( | |
summary='This is a Google-style docstring with long args.', | |
args=[ | |
ArgInfo(name='function_maker_handler_event_factory', | |
description='The function-maker-handler event factory ' | |
'responsible for making the function-maker-handler event. ' | |
'Use this whenever\nyou need a function-maker-handler event' | |
' made for you programmatically.'), | |
], | |
) | |
docstring = """This is a Google-style docstring with long args. | |
Here is some further and potentially long-winded explanation of the function. | |
Args: | |
function_maker_handler_event_factory: The function-maker-handler event factory | |
responsible for making the function-maker-handler event. Use this whenever | |
you need a function-maker-handler event made for you programmatically. | |
""" | |
docstring_info = docstrings.parse(docstring) | |
expected_docstring_info = DocstringInfo( | |
summary='This is a Google-style docstring with long args.\n\nHere is some further and potentially long-winded explanation of the function.', | |
args=[ | |
ArgInfo(name='function_maker_handler_event_factory', | |
description='The function-maker-handler event factory ' | |
'responsible for making the function-maker-handler event. ' | |
'Use this whenever\nyou need a function-maker-handler event' | |
' made for you programmatically.'), | |
], | |
) |
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 like it. I think this test case would fail rn since the default behavior is to ignore the \n and just display without them.
This was the issue I fixed but I think I have fixed it within the scope of args but not the name of the function and summary. I will work on this 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.
Another thing I noticed was that the name of the function is displayed as <name> - <summary>
. Is that how it should be? I only ask since we have a section called description where we display the summary.
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.
Another thing I noticed was that the name of the function is displayed as <name> - <summary>.
I think so, though maybe there are examples where it doesn't make sense and we can improve it. I'd have to give that some thought, but fortunately that's orthogonal to this change.
@@ -336,9 +342,10 @@ def _as_arg_name_and_type(text): | |||
None otherwise. | |||
""" | |||
tokens = text.split() | |||
is_type = any(c in "[](){}" for c in text) |
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.
What was the reason for this line?
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 haven't tested this, but if we add
:
after the first word in descriptions (line2 or later), the_is_arg_name()
function will be called and according to our current logic, anything that is just a word will be considered as an arg. I think we want a better way to identify an arg.
This was the initial reason for this. I just came up with this for the time being but i think that we need a better way to identify an arg name.
this would potentially close #448
Please review.