@@ -134,78 +134,126 @@ profile = black
134
134
135
135
</details >
136
136
137
- ### Flake8
137
+ ### pycodestyle
138
138
139
- [ Flake8 ] ( https://pypi. org/p/flake8/ ) is a code linter. It warns you of syntax errors,
140
- possible bugs, stylistic errors, etc. For the most part, Flake8 follows
139
+ [ pycodestyle ] ( https://pycodestyle.pycqa. org/ ) is a code linter. It warns you of syntax
140
+ errors, possible bugs, stylistic errors, etc. For the most part, pycodestyle follows
141
141
[ PEP 8] ( https://www.python.org/dev/peps/pep-0008/ ) when warning about stylistic errors.
142
142
There are a few deviations that cause incompatibilities with _ Black_ .
143
143
144
144
#### Configuration
145
145
146
146
```
147
147
max-line-length = 88
148
- extend- ignore = E203, E704
148
+ ignore = E203,E701
149
149
```
150
150
151
+ (labels/why-pycodestyle-warnings)=
152
+
151
153
#### Why those options above?
152
154
155
+ ##### ` max-line-length `
156
+
157
+ As with isort, pycodestyle should be configured to allow lines up to the length limit of
158
+ ` 88 ` , _ Black_ 's default.
159
+
160
+ ##### ` E203 `
161
+
153
162
In some cases, as determined by PEP 8, _ Black_ will enforce an equal amount of
154
- whitespace around slice operators. Due to this, Flake8 will raise
155
- ` E203 whitespace before ':' ` warnings. Since this warning is not PEP 8 compliant, Flake8
156
- should be configured to ignore it via ` extend-ignore = E203 ` .
163
+ whitespace around slice operators. Due to this, pycodestyle will raise
164
+ ` E203 whitespace before ':' ` warnings. Since this warning is not PEP 8 compliant, it
165
+ should be disabled.
166
+
167
+ ##### ` E701 ` / ` E704 `
168
+
169
+ _ Black_ will collapse implementations of classes and functions consisting solely of ` .. `
170
+ to a single line. This matches how such examples are formatted in PEP 8. It remains true
171
+ that in all other cases Black will prevent multiple statements on the same line, in
172
+ accordance with PEP 8 generally discouraging this.
173
+
174
+ However, ` pycodestyle ` does not mirror this logic and may raise
175
+ ` E701 multiple statements on one line (colon) ` in this situation. Its
176
+ disabled-by-default ` E704 multiple statements on one line (def) ` rule may also raise
177
+ warnings and should not be enabled.
178
+
179
+ ##### ` W503 `
157
180
158
181
When breaking a line, _ Black_ will break it before a binary operator. This is compliant
159
182
with PEP 8 as of
160
183
[ April 2016] ( https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b#diff-64ec08cc46db7540f18f2af46037f599 ) .
161
184
There's a disabled-by-default warning in Flake8 which goes against this PEP 8
162
185
recommendation called ` W503 line break before binary operator ` . It should not be enabled
163
- in your configuration.
164
-
165
- Also, as like with isort, flake8 should be configured to allow lines up to the length
166
- limit of ` 88 ` , _ Black_ 's default. This explains ` max-line-length = 88 ` .
186
+ in your configuration. You can use its counterpart
187
+ ` W504 line break after binary operator ` instead.
167
188
168
189
#### Formats
169
190
170
191
<details >
171
- <summary >.flake8 </summary >
192
+ <summary >setup.cfg, .pycodestyle, tox.ini </summary >
172
193
173
194
``` ini
174
- [flake8 ]
195
+ [pycodestyle ]
175
196
max-line-length = 88
176
- extend- ignore = E203, E704
197
+ ignore = E203,E701
177
198
```
178
199
179
200
</details >
180
201
181
- <details >
182
- <summary >setup.cfg</summary >
202
+ ### Flake8
183
203
184
- ``` ini
204
+ [ Flake8] ( https://pypi.org/p/flake8/ ) is a wrapper around multiple linters, including
205
+ pycodestyle. As such, it has many of the same issues.
206
+
207
+ #### Bugbear
208
+
209
+ It's recommended to use [ the Bugbear plugin] ( https://github.com/PyCQA/flake8-bugbear )
210
+ and enable
211
+ [ its B950 check] ( https://github.com/PyCQA/flake8-bugbear#opinionated-warnings#:~:text=you%20expect%20it.-,B950,-%3A%20Line%20too%20long )
212
+ instead of using Flake8's E501, because it aligns with
213
+ [ Black's 10% rule] ( labels/line-length ) .
214
+
215
+ Install Bugbear and use the following config:
216
+
217
+ ```
218
+ [flake8]
219
+ max-line-length = 80
220
+ extend-select = B950
221
+ extend-ignore = E203,E501,E701
222
+ ```
223
+
224
+ #### Minimal Configuration
225
+
226
+ In cases where you can't or don't want to install Bugbear, you can use this minimally
227
+ compatible config:
228
+
229
+ ```
185
230
[flake8]
186
231
max-line-length = 88
187
- extend-ignore = E203, E704
232
+ extend-ignore = E203,E701
188
233
```
189
234
190
- </details >
235
+ #### Why those options above?
236
+
237
+ See [ the pycodestyle section] ( labels/why-pycodestyle-warnings ) above.
238
+
239
+ #### Formats
191
240
192
241
<details >
193
- <summary >tox.ini</summary >
242
+ <summary >.flake8, setup.cfg, tox.ini</summary >
194
243
195
244
``` ini
196
245
[flake8]
197
246
max-line-length = 88
198
- extend-ignore = E203, E704
247
+ extend-ignore = E203,E701
199
248
```
200
249
201
250
</details >
202
251
203
252
### Pylint
204
253
205
- [ Pylint] ( https://pypi.org/p/pylint/ ) is also a code linter like Flake8. It has the same
206
- checks as flake8 and more. In particular, it has more formatting checks regarding style
207
- conventions like variable naming. With so many checks, Pylint is bound to have some
208
- mixed feelings about _ Black_ 's formatting style.
254
+ [ Pylint] ( https://pypi.org/p/pylint/ ) is also a code linter like Flake8. It has many of
255
+ the same checks as Flake8 and more. It particularly has more formatting checks regarding
256
+ style conventions like variable naming.
209
257
210
258
#### Configuration
211
259
@@ -252,35 +300,3 @@ max-line-length = "88"
252
300
```
253
301
254
302
</details >
255
-
256
- ### pycodestyle
257
-
258
- [ pycodestyle] ( https://pycodestyle.pycqa.org/ ) is also a code linter like Flake8.
259
-
260
- #### Configuration
261
-
262
- ```
263
- max-line-length = 88
264
- ignore = E203
265
- ```
266
-
267
- #### Why those options above?
268
-
269
- pycodestyle should be configured to only complain about lines that surpass ` 88 `
270
- characters via ` max_line_length = 88 ` .
271
-
272
- See
273
- [ Why are Flake8’s E203 and W503 violated?] ( https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated )
274
-
275
- #### Formats
276
-
277
- <details >
278
- <summary >setup.cfg</summary >
279
-
280
- ``` cfg
281
- [pycodestyle]
282
- ignore = E203
283
- max_line_length = 88
284
- ```
285
-
286
- </details >
0 commit comments