-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Fix 9918 #9932
Merged
Merged
Fix 9918 #9932
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,14 @@ def init_in_block(self, text): | |
""" | ||
return SpecialBlock.NOT_SPECIAL | ||
|
||
def end_of_special_style(self, line): | ||
""" | ||
Sets back the `in_block` attribute to `NOT_SPECIAL`. | ||
|
||
Useful for some docstrings where we may have to go back to `ARG_LIST` instead. | ||
""" | ||
self.in_block = SpecialBlock.NOT_SPECIAL | ||
Comment on lines
+138
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically the problem was that when a code block was nested in the argument list, we were returning to a not special style instead of returning to an arg list style. This new method overriden in the subclass |
||
|
||
def style_paragraph(self, paragraph, max_len, no_style=False, min_indent=None): | ||
""" | ||
Style `paragraph` (a list of lines) by making sure no line goes over `max_len`, except if the `no_style` flag | ||
|
@@ -220,6 +228,7 @@ def style(self, text, max_len=119, min_indent=None): | |
new_lines = [] | ||
paragraph = [] | ||
self.current_indent = "" | ||
self.previous_indent = None | ||
# If one of those is True, the paragraph should not be touched (code samples, lists...) | ||
no_style = False | ||
no_style_next = False | ||
|
@@ -251,7 +260,7 @@ def style(self, text, max_len=119, min_indent=None): | |
self.current_indent = indent | ||
elif not indent.startswith(self.current_indent): | ||
# If not, we are leaving the block when we unindent. | ||
self.in_block = SpecialBlock.NOT_SPECIAL | ||
self.end_of_special_style(paragraph[0]) | ||
|
||
if self.is_special_block(paragraph[0]): | ||
# Maybe we are starting a special block. | ||
|
@@ -326,13 +335,23 @@ def is_comment_or_textual_block(self, line): | |
|
||
def is_special_block(self, line): | ||
if self.is_no_style_block(line): | ||
if self.previous_indent is None and self.in_block == SpecialBlock.ARG_LIST: | ||
self.previous_indent = self.current_indent | ||
self.in_block = SpecialBlock.NO_STYLE | ||
return True | ||
if _re_arg_def.search(line) is not None: | ||
self.in_block = SpecialBlock.ARG_LIST | ||
return True | ||
return False | ||
|
||
def end_of_special_style(self, line): | ||
if self.previous_indent is not None and line.startswith(self.previous_indent): | ||
self.in_block = SpecialBlock.ARG_LIST | ||
self.current_indent = self.previous_indent | ||
else: | ||
self.in_block = SpecialBlock.NOT_SPECIAL | ||
self.previous_indent = None | ||
|
||
def init_in_block(self, text): | ||
lines = text.split("\n") | ||
while len(lines) > 0 and len(lines[0]) == 0: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That docstring had been changed to work around the doc-styling failure. This makes it the same as the PyTorch one,