diff --git a/README.rst b/README.rst index 54bdbc2..d87598e 100644 --- a/README.rst +++ b/README.rst @@ -58,76 +58,110 @@ If you'd like to do a PR we have development instructions `here `__. +.. _B024: + **B024**: Abstract base class has methods, but none of them are abstract. This is not necessarily an error, but you might have forgotten to add the @abstractmethod decorator, potentially in conjunction with @classmethod, @property and/or @staticmethod. +.. _B025: + **B025**: ``try-except`` block with duplicate exceptions found. This check identifies exception types that are specified in multiple ``except`` clauses. The first specification is the only one ever considered, so all others can be removed. +.. _B026: + **B026**: Star-arg unpacking after a keyword argument is strongly discouraged, because it only works when the keyword parameter is declared after all parameters supplied by the unpacked sequence, and this change of ordering can surprise and mislead readers. @@ -174,35 +226,63 @@ There was `cpython discussion of disallowing this syntax `_, but legacy usage and parser limitations make it difficult. +.. _B027: + **B027**: Empty method in abstract base class, but has no abstract decorator. Consider adding @abstractmethod. +.. _B028: + **B028**: No explicit stacklevel argument found. The warn method from the warnings module uses a stacklevel of 1 by default. This will only show a stack trace for the line on which the warn method is called. It is therefore recommended to use a stacklevel of 2 or greater to provide more information to the user. +.. _B029: + **B029**: Using ``except ():`` with an empty tuple does not handle/catch anything. Add exceptions to handle. +.. _B030: + **B030**: Except handlers should only be exception classes or tuples of exception classes. +.. _B031: + **B031**: Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage. Save the result to a list if the result is needed multiple times. +.. _B032: + **B032**: Possible unintentional type annotation (using ``:``). Did you mean to assign (using ``=``)? +.. _B033: + **B033**: Sets should not contain duplicate items. Duplicate items will be replaced with a single item at runtime. +.. _B034: + **B034**: Calls to `re.sub`, `re.subn` or `re.split` should pass `flags` or `count`/`maxsplit` as keyword arguments. It is commonly assumed that `flags` is the third positional parameter, forgetting about `count`/`maxsplit`, since many other `re` module functions are of the form `f(pattern, string, flags)`. +.. _B035: + **B035**: Found dict comprehension with a static key - either a constant value or variable not from the comprehension expression. This will result in a dict with a single key that was repeatedly overwritten. +.. _B036: + **B036**: Found ``except BaseException:`` without re-raising (no ``raise`` in the top-level of the ``except`` block). This catches all kinds of things (Exception, SystemExit, KeyboardInterrupt...) and may prevent a program from exiting as expected. +.. _B037: + **B037**: Found ``return ``, ``yield``, ``yield ``, or ``yield from `` in class ``__init__()`` method. No values should be returned or yielded, only bare ``return``\s are ok. +.. _B038: + **B038**: **Moved to B909** - Found a mutation of a mutable loop iterable inside the loop body. Changes to the iterable of a loop such as calls to `list.remove()` or via `del` can cause unintended bugs. +.. _B039: + **B039**: ``ContextVar`` with mutable literal or function call as default. This is only evaluated once, and all subsequent calls to `.get()` would return the same instance of the default. This uses the same logic as B006 and B008, including ignoring values in ``extend-immutable-calls``. +.. _B040: + **B040**: Caught exception with call to ``add_note`` not used. Did you forget to ``raise`` it? Opinionated warnings @@ -213,6 +293,8 @@ controversial. They may or may not apply to you, enable them explicitly in your configuration if you find them useful. Read below on how to enable. +.. _B901: + **B901**: Using ``return x`` in a generator function used to be syntactically invalid in Python 2. In Python 3 ``return x`` can be used in a generator as a return value in conjunction with ``yield from``. @@ -220,22 +302,30 @@ Users coming from Python 2 may expect the old behavior which might lead to bugs. Use native ``async def`` coroutines or mark intentional ``return x`` usage with ``# noqa`` on the same line. +.. _B902: + **B902**: Invalid first argument used for method. Use ``self`` for instance methods, and ``cls`` for class methods (which includes ``__new__`` and ``__init_subclass__``) or instance methods of metaclasses (detected as classes directly inheriting from ``type``). +.. _B903: + **B903**: Use ``collections.namedtuple`` (or ``typing.NamedTuple``) for data classes that only set attributes in an ``__init__`` method, and do nothing else. If the attributes should be mutable, define the attributes in ``__slots__`` to save per-instance memory and to prevent accidentally creating additional attributes on instances. +.. _B904: + **B904**: Within an ``except`` clause, raise exceptions with ``raise ... from err`` or ``raise ... from None`` to distinguish them from errors in exception handling. See `the exception chaining tutorial `_ for details. +.. _B905: + **B905**: ``zip()`` without an explicit `strict=` parameter set. ``strict=True`` causes the resulting iterator to raise a ``ValueError`` if the arguments are exhausted at differing lengths. @@ -244,18 +334,30 @@ Exclusions are `itertools.count ` handles it, but with different defaults, and they don't support specifying attributes such that a decorator will never match against a specified value ``obj.name`` even if decorated with ``@obj.name``.