Skip to content

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Jan 18, 2022

What does this PR do?

This PR makes the check_copies script a little bit more resilient by making sure it applies the styling on the docstrings when making/checking the copies. This will fixe issues like the one encountered in #15079

@sgugger sgugger requested a review from LysandreJik January 18, 2022 14:11


def style_file_docstrings(code_file, max_len=119, check_only=False):
def style_docstrings_in_code(code, max_len=119):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting this function in two so I have one I can use to format code in check_copies.

if has_indent:
code = f"class Bla:\n{code}"
result = black.format_str(code, mode=black.FileMode([black.TargetVersion.PY35], line_length=119))
result, _ = style_docstrings_in_code(result)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, clean!

@sgugger sgugger merged commit 1144d33 into master Jan 18, 2022
@sgugger sgugger deleted the copies_and_docstring_styling branch January 18, 2022 14:16
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

Successfully merging this pull request may close these issues.

2 participants