-
-
Notifications
You must be signed in to change notification settings - Fork 574
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
Fix bug regarding multiline docstrings #1695
Merged
timothycrosley
merged 1 commit into
PyCQA:develop
from
jonafato:fix-multiline-docstring-ending-on-line-add_import
Mar 23, 2021
Merged
Fix bug regarding multiline docstrings #1695
timothycrosley
merged 1 commit into
PyCQA:develop
from
jonafato:fix-multiline-docstring-ending-on-line-add_import
Mar 23, 2021
Conversation
This file contains 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
If a multiline docstring has its closing quotes at the end of a line instead of on a separate line, isort fails to properly add imports using the `add_imports` config option; instead, it adds the desired imports into the middle of the docstring as illustrated below. While PEP 257 (and other guides) advises that closing quotes appear on their own line, `isort` should not fail here. This change adds a check for closing docstrings at the end of a line in addition to the existing line start check for all comment indicators. A new section of the `test_add_imports` test explicitly tests multiline imports and this failure scenario specifically. --- A working example: ```python """My module. Provides example functionality. """ print("hello, world") ``` Running `isort --add-import "from __future__ import annotations"` produces the following as expected: ```python """My module. Provides example functionality. """ from __future__ import annotations print("hello, world") ``` --- The failure behavior described: ```python """My module. Provides example functionality.""" print("hello, world") ``` Running `isort --add-import "from __future__ import annotations"` as above produces the following result: ```python """My module. from __future__ import annotations Provides example functionality.""" print("hello, world") ``` Subsequent executions add more import lines into the docstring. This behavior occurs even if the file already has the desired imports.
jonafato
force-pushed
the
fix-multiline-docstring-ending-on-line-add_import
branch
from
March 22, 2021 17:55
c03a35d
to
2ccb497
Compare
Thanks for finding and fixing this issue! |
This was referenced Jun 21, 2021
Closed
chore(deps): update precommit hook pycqa/isort to v5.9.0
browniebroke/cert-transparency-slackbot#164
Merged
This was referenced Sep 5, 2021
This was referenced Sep 13, 2021
1 task
1 task
This was referenced Oct 18, 2021
Closed
1 task
1 task
This was referenced Nov 6, 2021
1 task
1 task
1 task
This was referenced Apr 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If a multiline docstring has its closing quotes at the end of a line
instead of on a separate line, isort fails to properly add imports using
the
add_imports
config option; instead, it adds the desired importsinto the middle of the docstring as illustrated below. While PEP 257
(and other guides) advises that closing quotes appear on their own line,
isort
should not fail here.This change adds a check for closing docstrings at the end of a line in
addition to the existing line start check for all comment indicators. A
new section of the
test_add_imports
test explicitly tests multilineimports and this failure scenario specifically.
A working example:
Running
isort --add-import "from __future__ import annotations"
produces the following as expected:
The failure behavior described:
Running
isort --add-import "from __future__ import annotations"
asabove produces the following result:
Subsequent executions add more import lines into the docstring. This
behavior occurs even if the file already has the desired imports.