Opened 8 years ago
Closed 8 years ago
#27182 closed Cleanup/optimization (needsinfo)
Some import statement use backslashes instead of parentheses
Reported by: | Chris Jerdonek | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Someday/Maybe | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Some import statements in Django's code base use backslashes to break long lines instead of parentheses (at least 21 occurrences if you search the code base for "import \
"). Here is one example (direct link here):
from django.db.backends.mysql.base import \ DatabaseWrapper as MySQLDatabaseWrapper
These go against Django's coding style standards, which say in the "Imports" section to use parentheses:
Break long lines using parentheses and indent continuation lines by 4 spaces.
Django's coding style also says to follow PEP 8, which says this:
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
I believe this issue is caused by a bug in isort, since the isort section of Django's setup.cfg
already sets multi_line_output=5
(which means to use parentheses). I tried filing an issue about this here.
Change History (5)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 8 years ago
For the record, most (or perhaps all, I haven't checked) of these occurrences would also go away if Django's line_length
isort setting (direct link here) were increased from 79 to something longer like 119. Even though Django's coding style permits up to 119 characters, the isort configuration setting has the effect of making 79 a hard limit instead of a soft one in the case of import statements.
comment:4 by , 8 years ago
Triage Stage: | Accepted → Someday/Maybe |
---|
Bumping to Someday/Maybe as it's not actionable until the isort issue fixed. I explained in #27173 why changing isort's max_line_length
isn't desired.
comment:5 by , 8 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Django will adapt as soon as isort fixes the issue. I don't see a need to keep a ticket open for it here.
That would indeed be nice to fix. We have always been at war with backslashes.