flake8-get-chaining
plugin checks for chained dict.get
calls and makes sure valid defaults are provided.
Install from pip
with:
$ pip install flake8-get-chaining
It will then automatically be run as part of flake8
; you can check it has been picked up with:
$ flake8 --version
5.0.4 (flake8-get-chaining: 0.1.0, mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.9 on Linux
DGC1001: Missing default argument when chaining dict.get
This warning is emitted when dict.get
calls are chained, and no default was provided.
Example: my_dict.get("foo").get("bar")
DGC1002: Invalid default argument when chaining dict.get
This warning is emitted when dict.get
calls are chained, and the default value is
invalid (i.e not a dict nor an identifier)
Example: my_dict.get("foo", "bar").get("baz")