gh-81283: compiler: remove indent from docstring by methane · Pull Request #106411 · python/cpython (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation11 Commits9 Checks0 Files changed
Conversation
This file contains hidden or 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
[ Show hidden characters]({{ revealButtonHref }})
Member
methane commented
•
edited by github-actionsbot
Loading
# sqlalchemy/orm/__pycache__
# main:
ls -lS | head
-rw-r--r-- 1 inada-n staff 197484 Jul 4 18:06 session.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 169161 Jul 4 18:06 mapper.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 137441 Jul 4 18:06 events.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 130456 Jul 4 18:06 relationships.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 128389 Jul 4 18:06 query.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 104012 Jul 4 18:06 strategies.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 101628 Jul 4 18:06 _orm_constructors.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 100939 Jul 4 18:06 context.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 98761 Jul 4 18:06 attributes.cpython-313.pyc
# c-cleandoc:
total 4432
-rw-r--r-- 1 inada-n staff 187185 Jul 4 21:04 session.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 163634 Jul 4 21:04 mapper.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 127659 Jul 4 21:04 relationships.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 124634 Jul 4 21:04 events.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 119689 Jul 4 21:04 query.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 103889 Jul 4 21:04 strategies.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 100432 Jul 4 21:04 context.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 97329 Jul 4 21:04 attributes.cpython-313.pyc
-rw-r--r-- 1 inada-n staff 96105 Jul 4 21:04 _orm_constructors.cpython-313.pyc
# file size of session.pyc
>>> a,b=197484,187185
>>> (a-b)*100/a
5.215106033906545
lines = doc.expandtabs().split('\n') |
---|
except UnicodeError: |
return None |
else: |
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' |
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); |
} |
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.
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(' ')) |
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!
Carreau added a commit to Carreau/ipython that referenced this pull request
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.
Carreau added a commit to Carreau/ipython that referenced this pull request
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.
Carreau added a commit to ipython/ipython that referenced this pull request
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.
Reviewers
gpshead gpshead left review comments
merwok merwok left review comments
iritkatriel iritkatriel left review comments
sunmy2019 sunmy2019 left review comments
markshannon Awaiting requested review from markshannon markshannon is a code owner