-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-81283: compiler: remove indent from docstring #106411
Conversation
|
lines = doc.expandtabs().split('\n') | ||
except UnicodeError: | ||
return None | ||
else: |
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 removed this try-except-else block because Python 3 don't autodecode from bytes.
If doc is bytes, doc.split('\n')
raises TypeError, not UnicodeError.
@@ -1287,14 +1287,14 @@ def optionflags(): r""" | |||
treated as equal: | |||
|
|||
>>> def f(x): | |||
... '>>> print(1, 2, 3)\n 1 2\n 3' | |||
... '\n>>> print(1, 2, 3)\n 1 2\n 3' |
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.
This change is needed to avoid dedenting output examples.
|
||
Py_DECREF(doc); | ||
return PyUnicode_FromStringAndSize(buff, w - buff); | ||
} |
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'm not sure the dedent logic belongs in compile.c.
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.
Because this dedent logic is very specific for docstring.
We can not use this logic in other place except inspect.cleandoc
.
If we reuse this logic in inspect.cleandoc
, it would be:
doc = compiler.cleandoc(doc).strip('\n')
# Find minimum indentation of any non-blank lines after first line. | ||
margin = sys.maxsize | ||
for line in lines[1:]: | ||
content = len(line.lstrip(' ')) |
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 changed from line.lstrip()
to line.lstrip(' ')
for better compatibility between inspect.cleandoc and compiler.cleandoc.
Co-authored-by: Éric <merwok@netwok.org>
With the forum discussion ongoing, and the other discussion about requiring reviews, I think this could have waited a little bit to get a review approval. On the other hand it’s not a huge change! |
Since python/cpython#106411, it look like cpython is removing leading space and indent. We therefore need conditional check, until we decide Wether this is a problem we want to deal with or not.
Since python/cpython#106411, it look like cpython is removing leading space and indent. We therefore need conditional check, until we decide Wether this is a problem we want to deal with or not.
Since python/cpython#106411, it look like cpython is removing leading space and indent. We therefore need conditional check, until we decide Wether this is a problem we want to deal with or not.
📚 Documentation preview 📚: https://cpython-previews--106411.org.readthedocs.build/