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.
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.
|
|
||
| >>> 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.
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.
I'm not sure the dedent logic belongs in compile.c.
There was a problem hiding this comment.
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.
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/