@@ -35,10 +35,13 @@ them.
35
35
Python style
36
36
============
37
37
38
- * Please conform to the indentation style dictated in the ``.editorconfig``
39
- file. We recommend using a text editor with `EditorConfig`_ support to avoid
40
- indentation and whitespace issues. The Python files use 4 spaces for
41
- indentation and the HTML files use 2 spaces.
38
+ * All files should be formatted using the `black`_ auto-formatter. This will be
39
+ run by ``pre-commit`` if that is configured.
40
+
41
+ * The project repository includes an ``.editorconfig`` file. We recommend using
42
+ a text editor with `EditorConfig`_ support to avoid indentation and
43
+ whitespace issues. The Python files use 4 spaces for indentation and the HTML
44
+ files use 2 spaces.
42
45
43
46
* Unless otherwise specified, follow :pep:`8`.
44
47
@@ -51,33 +54,11 @@ Python style
51
54
52
55
An exception to :pep:`8` is our rules on line lengths. Don't limit lines of
53
56
code to 79 characters if it means the code looks significantly uglier or is
54
- harder to read. We allow up to 119 characters as this is the width of GitHub
55
- code review; anything longer requires horizontal scrolling which makes review
56
- more difficult. This check is included when you run ``flake8``. Documentation,
57
+ harder to read. We allow up to 88 characters as this is the line length used
58
+ by ``black``. This check is included when you run ``flake8``. Documentation,
57
59
comments, and docstrings should be wrapped at 79 characters, even though
58
60
:pep:`8` suggests 72.
59
61
60
- * Use four spaces for indentation.
61
-
62
- * Use four space hanging indentation rather than vertical alignment::
63
-
64
- raise AttributeError(
65
- 'Here is a multiline error message '
66
- 'shortened for clarity.'
67
- )
68
-
69
- Instead of::
70
-
71
- raise AttributeError('Here is a multiline error message '
72
- 'shortened for clarity.')
73
-
74
- This makes better use of space and avoids having to realign strings if the
75
- length of the first line changes.
76
-
77
- * Use single quotes for strings, or a double quote if the string contains a
78
- single quote. Don't waste time doing unrelated refactoring of existing code
79
- to conform to this style.
80
-
81
62
* String variable interpolation may use
82
63
:py:ref:`%-formatting <old-string-formatting>`, :py:ref:`f-strings
83
64
<f-strings>`, or :py:meth:`str.format` as appropriate, with the goal of
@@ -146,6 +127,10 @@ Python style
146
127
"""
147
128
...
148
129
130
+ .. versionchanged:: 4.0.3
131
+
132
+ All Python code in Django was reformatted with `black`_.
133
+
149
134
.. _coding-style-imports:
150
135
151
136
Imports
@@ -397,5 +382,6 @@ JavaScript style
397
382
For details about the JavaScript code style used by Django, see
398
383
:doc:`javascript`.
399
384
385
+ .. _black: https://black.readthedocs.io/en/stable/
400
386
.. _editorconfig: https://editorconfig.org/
401
387
.. _flake8: https://pypi.org/project/flake8/
0 commit comments