@@ -8,9 +8,9 @@ flake8-bugbear
8
8
.. image :: https://img.shields.io/badge/code%20style-black-000000.svg
9
9
:target: https://github.com/psf/black
10
10
11
- A plugin for Flake8 finding likely bugs and design problems in your
12
- program. Contains warnings that don't belong in pyflakes and
13
- pycodestyle::
11
+ A plugin for `` flake8 `` finding likely bugs and design problems in your
12
+ program. Contains warnings that don't belong in `` pyflakes `` and
13
+ `` pycodestyle `` ::
14
14
15
15
bug·bear (bŭg′bâr′)
16
16
n.
@@ -57,7 +57,7 @@ List of warnings
57
57
**B001 **: Do not use bare ``except: ``, it also catches unexpected events
58
58
like memory errors, interrupts, system exit, and so on. Prefer ``except
59
59
Exception: ``. If you're sure what you're doing, be explicit and write
60
- ``except BaseException: ``. Disable E722 to avoid duplicate warnings.
60
+ ``except BaseException: ``. Disable `` E722 `` to avoid duplicate warnings.
61
61
62
62
**B002 **: Python does not support the unary prefix increment. Writing
63
63
``++n `` is equivalent to ``+(+(n)) ``, which equals ``n ``. You meant ``n
@@ -132,12 +132,15 @@ data available in ``ex``.
132
132
133
133
**B018 **: Found useless expression. Either assign it to a variable or remove it.
134
134
135
+ **B019 **: Use of ``functools.lru_cache `` or ``functools.cache `` on class methods
136
+ can lead to memory leaks. The cache may retain instance references, preventing
137
+ garbage collection.
138
+
135
139
**B020 **: Loop control variable overrides iterable it iterates
136
140
137
141
**B021 **: f-string used as docstring. This will be interpreted by python
138
142
as a joined string rather than a docstring.
139
143
140
-
141
144
Opinionated warnings
142
145
~~~~~~~~~~~~~~~~~~~~
143
146
@@ -170,15 +173,15 @@ See `the exception chaining tutorial <https://docs.python.org/3/tutorial/errors.
170
173
for details.
171
174
172
175
**B950 **: Line too long. This is a pragmatic equivalent of
173
- ``pycodestyle ``'s E501: it considers "max-line-length" but only triggers
176
+ ``pycodestyle ``'s `` E501 `` : it considers "max-line-length" but only triggers
174
177
when the value has been exceeded by **more than 10% **. You will no
175
178
longer be forced to reformat code due to the closing parenthesis being
176
179
one character too far to satisfy the linter. At the same time, if you do
177
180
significantly violate the line length, you will receive a message that
178
181
states what the actual limit is. This is inspired by Raymond Hettinger's
179
182
`"Beyond PEP 8" talk <https://www.youtube.com/watch?v=wf-BqAjZb8M >`_ and
180
183
highway patrol not stopping you if you drive < 5mph too fast. Disable
181
- E501 to avoid duplicate warnings. Like E501, this error ignores long shebangs
184
+ `` E501 `` to avoid duplicate warnings. Like `` E501 `` , this error ignores long shebangs
182
185
on the first line and urls or paths that are on their own line::
183
186
184
187
#! long shebang ignored
@@ -192,41 +195,57 @@ on the first line and urls or paths that are on their own line::
192
195
How to enable opinionated warnings
193
196
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194
197
195
- To enable these checks, specify a ``--select `` command-line option or
196
- ``select= `` option in your config file. As of Flake8 3.0, this option
197
- is a whitelist (checks not listed are being implicitly disabled), so you
198
- have to explicitly specify all checks you want enabled. For example::
199
-
200
- [flake8]
201
- max-line-length = 80
202
- max-complexity = 12
203
- ...
204
- ignore = E501
205
- select = C,E,F,W,B,B901
206
-
207
- Note that we're enabling the complexity checks, the PEP8 ``pycodestyle ``
208
- errors and warnings, the pyflakes fatals and all default Bugbear checks.
209
- Finally, we're also specifying B901 as a check that we want enabled.
210
- Some checks might need other flake8 checks disabled - e.g. E501 must be
211
- disabled for B950 to be hit.
212
-
213
- If you'd like all optional warnings to be enabled for you (future proof
214
- your config!), say ``B9 `` instead of ``B901 ``. You will need Flake8 3.2+
215
- for this feature.
216
-
217
- Note that ``pycodestyle `` also has a bunch of warnings that are disabled
218
- by default. Those get enabled as soon as there is an ``ignore = `` line
219
- in your configuration. I think this behavior is surprising so Bugbear's
198
+ To enable Bugbear's opinionated checks (``B9xx ``), specify an ``--extend-select ``
199
+ command-line option or ``extend-select= `` option in your config file
200
+ (requires ``flake8 >=4.0 ``)::
201
+
202
+ [flake8]
203
+ max-line-length = 80
204
+ max-complexity = 12
205
+ ...
206
+ extend-ignore = E501
207
+ extend-select = B950
208
+
209
+ Some of Bugbear's checks require other ``flake8 `` checks disabled - e.g. ``E501 `` must
210
+ be disabled when enabling ``B950 ``.
211
+
212
+ If you'd like all optional warnings to be enabled for you (future proof your config!),
213
+ say ``B9 `` instead of ``B950 ``. You will need ``flake8 >=3.2 `` for this feature.
214
+
215
+ For ``flake8 <=4.0 ``, you will need to use the ``--select `` command-line option or
216
+ ``select= `` option in your config file. For ``flake8 >=3.0 ``, this option is a whitelist
217
+ (checks not listed are implicitly disabled), so you have to explicitly specify all
218
+ checks you want enabled (e.g. ``select = C,E,F,W,B,B950 ``).
219
+
220
+ The ``--extend-ignore `` command-line option and ``extend-ignore= `` config file option
221
+ require ``flake8 >=3.6 ``. For older ``flake8 `` versions, the ``--ignore `` and
222
+ ``ignore= `` options can be used. Using ``ignore `` will override all codes that are
223
+ disabled by default from all installed linters, so you will need to specify these codes
224
+ in your configuration to silence them. I think this behavior is surprising so Bugbear's
220
225
opinionated warnings require explicit selection.
221
226
227
+ **Note: ** Bugbear's enforcement of explicit opinionated warning selection is deprecated
228
+ and will be removed in a future release. It is recommended to use ``extend-ignore `` and
229
+ ``extend-select `` in your ``flake8 `` configuration to avoid implicitly altering selected
230
+ and/or ignored codes.
231
+
222
232
Configuration
223
233
-------------
224
234
225
235
The plugin currently has one setting:
226
236
227
237
``extend-immutable-calls ``: Specify a list of additional immutable calls.
228
238
This could be useful, when using other libraries that provide more immutable calls,
229
- beside those already handled by ``flake8-bugbear ``. Calls to these method will no longer raise a ``B008 `` warning.
239
+ beside those already handled by ``flake8-bugbear ``. Calls to these method will no longer
240
+ raise a ``B008 `` warning.
241
+
242
+ For example::
243
+
244
+ [flake8]
245
+ max-line-length = 80
246
+ max-complexity = 12
247
+ ...
248
+ extend-immutable-calls = pathlib.Path, Path
230
249
231
250
Tests / Lints
232
251
---------------
0 commit comments