Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
d5083c33
Unverified
Commit
d5083c33
authored
Feb 18, 2022
by
Sylvain Gugger
Committed by
GitHub
Feb 18, 2022
Browse files
style_doc handles decorators in examples (#15719)
parent
ae1f8350
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
utils/style_doc.py
utils/style_doc.py
+10
-1
No files found.
utils/style_doc.py
View file @
d5083c33
...
...
@@ -171,9 +171,14 @@ def format_code_example(code: str, max_len: int, in_docstring: bool = False):
# black may have added some new lines, we remove them
code_sample
=
code_sample
.
strip
()
in_triple_quotes
=
False
in_decorator
=
False
for
line
in
code_sample
.
strip
().
split
(
"
\n
"
):
if
has_doctest
and
not
is_empty_line
(
line
):
prefix
=
"... "
if
line
.
startswith
(
" "
)
or
line
in
[
")"
,
"]"
,
"}"
]
or
in_triple_quotes
else
">>> "
prefix
=
(
"... "
if
line
.
startswith
(
" "
)
or
line
in
[
")"
,
"]"
,
"}"
]
or
in_triple_quotes
or
in_decorator
else
">>> "
)
else
:
prefix
=
""
indent_str
=
""
if
is_empty_line
(
line
)
else
(
" "
*
indent
)
...
...
@@ -181,6 +186,10 @@ def format_code_example(code: str, max_len: int, in_docstring: bool = False):
if
'"""'
in
line
:
in_triple_quotes
=
not
in_triple_quotes
if
line
.
startswith
(
" "
):
in_decorator
=
False
if
line
.
startswith
(
"@"
):
in_decorator
=
True
formatted_lines
.
extend
([
" "
*
indent
+
line
for
line
in
output
.
split
(
"
\n
"
)])
if
not
output
.
endswith
(
"===PT-TF-SPLIT==="
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment