Skip to content

gh-81283: compiler: remove indent from docstring #106411

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

Merged
merged 9 commits into from
Jul 15, 2023
Merged

Conversation

methane
Copy link
Member

@methane methane commented Jul 4, 2023

@methane
Copy link
Member Author

methane commented Jul 4, 2023

# 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:
Copy link
Member Author

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'
Copy link
Member Author

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);
}
Copy link
Member

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.

Copy link
Member Author

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(' '))
Copy link
Member Author

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.

@methane methane merged commit 2566b74 into python:main Jul 15, 2023
@methane methane deleted the c-cleandoc branch July 15, 2023 10:33
@merwok
Copy link
Member

merwok commented Jul 24, 2023

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 Dec 31, 2023
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 Dec 31, 2023
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 Dec 31, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants