Skip to content

Latest commit

 

History

History
538 lines (398 loc) · 18 KB

checks.md

File metadata and controls

538 lines (398 loc) · 18 KB

Checks

Codes

  • FTP000: internal errors
  • FTP001 - FTP199: general purpose checks
  • FTP200 - FTP219: flask and werkzeug checks
  • FTP220 - FTP239: requests checks

FTP000

Error while loading this plugin or any other internal error

FTP001

Checks if one of the debug modules pdb, ipdb, pudb, wdb, pdbpp and debugger is used

FTP002

Checks if the debug builtin breakpoint is used

FTP003

Checks for usage of datetime.datetime.utcnow. The value is current UTC time but without any timezone assigned. Preferred is datetime.datetime.now with a timezone parameter. The check is only active if datetime.datetime.utcnow is somehow imported.

FTP004

Checks if a module/file name follows the PEP-8 convention

FTP005

Find duplicate class fields (multiple assigns to the same name in the class body). No functions or blocks are checked.

FTP006

Find any usage of unicode directionality formatting characters. These characters are used to display left-to-right/right-to-left text in the same line and are interpreted by the bidi algorithm. However, having these characters in source code can lead to attacks like early returns because the code is executed in another way than written. A normal code review will not detect these issues. The easiest way is to ban these characters. For details see this paper.

FTP007

Checks for usage of datetime.datetime.utcfromtimestamp. The value is current UTC time but without any timezone assigned. Preferred is datetime.datetime.fromtimestamp with a timezone parameter. The check is only active if datetime.datetime.utcfromtimestamp is somehow imported.

FTP008

Checks for unnecessary parenthesis, like print((1,2,3)) and also one line return statements like return (a, b). By default, the parenthesis of a return of a single element tuple is kept. This can be disabled by using enforce-parens-in-return-single-element-tuple

FTP009

Checks for classes extending BaseException

FTP010

Checks if a disallowed developer comment identifier is used. Please refer to the developer comment configuration.

FTP011

Checks if the tracking id reference in a developer comment is missing. Please refer to the developer comment configuration.

FTP012

Checks if an invalid tracking id reference in a developer comment is used. Please refer to the developer comment configuration.

FTP013

Checks if the description of a developer comment is missing. Please refer to the developer comment configuration.

FTP014

Checks for calls of urllib.parse.urlparse. This function can parse a special ;parameters part inside the path which is not recommended. The function urllib.parse.urlsplit does basically the same but ignores the parameters part and is therefore faster. The check is only active if urllib.parse.urlparse is somehow imported.

FTP015

Checks for imports of pkg_resources. This module should not be used anymore as better and faster alternatives are available in importlib and its backports

FTP016

Find usage of python2 metaclass declaration with __metaclass__ inside the class body. Instead use metaclass= in the class signature.

FTP017

Find legacy calls of typing.NamedTuple. Instead, extend typing.NamedTuple by creating a new class

FTP018

Find legacy calls of typing.TypedDict. Instead, extend typing.TypedDict by creating a new class

FTP019

reserved for a future check

FTP020

Checks if an encoding comment (# -*- coding: utf-8 -*-) is used. These comments are not needed in python 3 anymore

FTP021

Checks if a string value (or a part of it) can be replaced with string.ascii_letters

FTP022

Checks if a string value (or a part of it) can be replaced with string.ascii_lowercase

FTP023

Checks if a string value (or a part of it) can be replaced with string.ascii_uppercase

FTP024

Checks if a string value (or a part of it) can be replaced with string.digits

FTP025

Checks for isinstance calls with an one-element tuple

FTP026

Checks for imports the easteregg modules this, antigravity, __hello__ and __phello__,

FTP027

Checks for easteregg imports of the __future__ module: braces and barry_as_FLUFL.

FTP028

Find empty doc comments (#:)

FTP029

Find enumeration loops where the index variable is named _. Use a classical for loop instead

FTP030

Checks if any unnecessary future import is used

FTP031

Checks if percentage formatting is used in logging calls

FTP032

Checks if a f-string is used in logging calls

FTP033

Checks if str.format is used in logging calls.

FTP034

Checks if exc_info=True is used in exception logging calls. This argument is redundant.

FTP035

Checks if the deprecated logging method warn is used.

FTP036

Checks if exc_info=True is used in error logging calls. Use exception instead.

FTP037

Checks if keys used in the extra dict of logging calls clashes with existing logging.LogRecord fields. This can lead to errors during runtime

FTP038

Checks if float('NaN') is used, because math.nan should be preferred

FTP039

Check if a dunder is used in the middle of the name like a__b. Double underscores at the start and at the end are ignored.

FTP040

Checks if a file is in a folder without an init.py file. The error is reported on the first line of the file. If files are checked which should not be part of a namespace package (e.g. setup.py), a noqa comment or "per-file-ignores" can be used.

FTP041

Checks if a module is used which is not specified as a requirement. Please refer to the requirement check configuration.

FTP042

Checks if a class defines a magic method like __hex__ which is legacy from python2 and is no longer needed

FTP043

Checks if a function starting with get_ has at least one return or yield statement. The function will be ignored, if it's a stub (e.g. just has a pass statement or only throws an exception)

FTP044

Checks if an exception is raised from itself, e.g. raise exc from exc

FTP045

Checks if a bad function like help or exit is called

FTP046

Checks if an except block only contains a reraise of the caught exception

FTP047

Checks if a too generic exception (Exception and BaseException) is raised

FTP048

Checks if a float is used as a dict key. Floats have precision errors, so using them as keys is unreliable and can lead to errors

FTP049

Checks if a single element unpacking is used (e.g. (a,) = my_list). It can be simplified to a = mylist[0]

FTP050

Checks if a print statement is used

FTP051

Checks if a pprint.pprint statement is used

FTP052

Checks if a pprint.pp statement is used

FTP053

Checks if a pprint.PrettyPrinter statement is used

FTP054

Checks if a union type annotation can utilize the new syntax of PEP 604. For example, a: Union[Foo, Bar] can be rewritten to a: Foo|bar. This check is only active when at least one of the following conditions is true:

  • running python 3.10+
  • a from __future__ import annotations import is present in the module
  • the current code is inside a typing.TYPE_CHECKING block

Also, the check will only consider type annotations (to prevent invalid syntax) if at least one of the following conditions is true:

  • python 3.9 or below is used
  • the code is not inside a typing.TYPE_CHECKING block

FTP055

Checks if an optional type annotations can utilize the new syntax of PEP 604. For example, a: Optional[Foo] can be rewritten to a: Foo|None. For more details see FTP054

FTP056

Checks if a builtin alias in the typing module can be rewritten as the builtin itself as of PEP 585. E.g. typing.List[str] can be changed to list[str].

This check is only active when at least one of the following conditions is true:

  • running python 3.9+
  • a from __future__ import annotations import is present in the module
  • the current code is inside a typing.TYPE_CHECKING block

Also, the check will only consider type annotations (to prevent invalid syntax) if at least one of the following conditions is true:

  • the code is not inside a typing.TYPE_CHECKING block

FTP057

Checks if relative imports are used

FTP058

Checks if an unnecessary import alias is used, e.g. import foo as foo

FTP059

Checks if an argument in a function call has a pointless starred expression. For single starred expressions, lists, dicts, tuples, sets, strings and bytes are checked. As an example, foo(*[1, 2, 3]) can be simplified to foo(1, 2, 3). For double starred expressions, only dicts are checked. An issue is only raised if all keys of the dict are strings, else the dict is not considered static and will be ignore. As an example, foo(**{'a': 1, 'b': 2}) can be simplified to foo(a=1, b=2).

FTP060

Checks if a percentage formatting is used

FTP061

Checks if "".format() is used

FTP062

Checks if str.format is used

FTP063

Check if contextlib.wraps is used. The call will work at runtime, but wraps comes originally from functools.wraps and contextlib doesn't re-export it, so it should be considered as an implementation detail which is not stable. Therefore functools.wraps should be used.

FTP064

Check if __debug__ is used. This constant is false when python is not started in optimized -O mode. Because this mode is basically never used and having code which only runs when not running in a special mode can have unexpected side effects, this constant should not be used.

FTP065

Check if collections.namedtuple is used. typing.NamedTuple should be used instead, since it integrates nicer with IDE's and type checkers

FTP066

Check if an enum.Enum subclass is used which also extends int, so e.g. class MyEnum(Enum, int). For that the alias enum.IntEnum can be used

FTP067

Check if an enum.Enum subclass is used which also extends str, so e.g. class MyEnum(Enum, str). For that the alias enum.StrEnum can be used. The check is only active for python3.11+

FTP068

Check if a call of subprocess.run has the value subprocess.PIPE assigned to both stdout and stderr. In this case, it can be simplified to capture_output=True.

FTP069

Check if a variable has a name which can lead to confusion like pi = 5 or nan = 4.

FTP070

Checks for super calls with arguments

FTP071

Check for assign and return statements. Normally the check also finds statements like a: int = 2; return a. To configure the step to ignore assignments with annotations, use ignore-annotation-in-assign-return. By default the check is disabled if the variable name happens to be part of a global/nonlocal statement. The check is also suppressed, if the assign-return is part of a try block and in the corresponding finally block the variable is used

FTP072

Checks for unicode string prefixes like u"abc"

FTP073

Checks for the usage of functools.lru_cache which can be replaced with functools.cache. The check is only active if functools.lru_cache is somehow imported.

FTP074

Checks if a functools.cache or functools.lru_cache is used on a class method. Since the self argument is cached as well, garbage collection is blocked, leading to memory leaks. If the method is decorated with staticmethod or classmethod, the issue doesn't happen. Note, that the check only considers methods which are defined as a direct child of a class.

FTP075

Check if subprocess.run or subprocess.Popen is called with universal_newlines. This keyword argument can be replaced with text which is more readable

FTP076

Checks for import of from re import DEBUG or usage of re.DEBUG

FTP078

Checks for type comments which should be replaced by annotations. type:ignore is ignored

FTP077

Check if in a type annotation containing a union, None always comes last. For instance a: int|float|None is okay, but a: int|None|float is not. This check does not work for unions using typing.Union and does also not consider typing.Optional

FTP079

Checks for unnecessary lambda statement which can be replaced with their built-in function alternative, e.g. lambda: [] with list

FTP080

Checks for implicit concatenated strings on the same line

FTP081

Checks for missing onerror keyword in os.walk. The check is only active if os.walk is somehow imported.

FTP082

Checks for unnecessary usage of metaclass=abc.ABCMeta, which can be simplified to abc.ABC

FTP083

Checks for unnecessary usage of str(), like str("a")

FTP084

Checks for unnecessary usage of int(), like int(1)

FTP085

Checks for unnecessary usage of float(), like float(1.1)

FTP086

Checks for unnecessary usage of bool(), like bool(True)

FTP087

Checks for imports of xml.etree.cElementTree

FTP088

Checks for the usage of io.open which can be simplified to open.

FTP089

Checks for the usage of OSError aliases EnvironmentError, IOError and WindowsError. In addition, it also finds usage and imports of socket.error and select.error. In this case, calls like raise socket.error() are not checked.

FTP090

Checks for unsorted __all__ attributes on any level. The check is only done if the type is a list, tuple or set during parsing (e.g. list is a function and not a list during parsing). Only items which are strings are used in the sort check, all others are ignored.

FTP091

Checks if backslashes are used to split long lines.

FTP092

Checks for unnecessary usage of 0 as starting point with no step size defined in range call.

FTP093

Find functions starting with is_/have_/has_/can_ which have a non-boolean return type. typing.TypeGuard is accepted as an alternative to a boolean. Functions with no return type annotation are ignored.

FTP094

Find cases where the __slot__ attribute is assigned something else than a tuple or dict, like __slots__ = [] or __slots__ = get_slots(). In general, using e.g. a list or single string is fine, but always using a tuple or dict is more consistent and recommended

FTP095

Checks for unnecessary use of unpack operators.

FTP096

Find functions which are decorated with property, classmethod or staticmethod but are outside of a class.

FTP097

Find enums without enum.unique decorator to make sure no duplicate values are assigned.

FTP098

Checks for usage of multiprocessing.set_start_method. A multiprocessing Context should be used instead.

FTP099

Since python 3.11 the datetime.timezone.utc constant is also accessible with datetime.UTC which is found by this check

FTP100

Find print("") which can be simplified to print()

FTP101

Find unpack operators inside of a dict which can be rewritten with the dict union operator. E.g. {**a, **b} can be rewritten to a|b and {**a, 'b': 2} to a|{'b': 2}. The check ignores unpacks in the middle of the dict, e.g. {'a': 1, **b, 'c': 3}. This check is only active when running python 3.9+.

FTP102

Find Path(".") of pathlib.Path which can be simplified to Path()

FTP103

Find usage of the OS dependent pathlib classes pathlib.PosixPath, pathlib.WindowsPath, pathlib.PurePosixPath and pathlib.PureWindowsPath. These classes can be replaced with pathlib.Path and pathlib.PurePath, because they are OS independent and create the correct OS dependent class behind the scenes

FTP104

Find typing.Never and typing.NoReturn in unions. These types are redundant in unions and can be removed

FTP105

Find nested typing.Union types like Union[Union[int, str], float]. These can be simplified to Union[int, str, float]

FTP106

Find typing.Union with a single element, e.g. Union[int]. This can be simplified to int

FTP107

Find usage of typing.Never in return annotations. Instead use typing.NoReturn

FTP108

Find usage of typing.NoReturn in non-return annotations (arguments and assignments). Instead use typing.Never

FTP109

Checks for unnecessary usage of bytes(), like bytes(b'abc'')

FTP110

Find str() which can be simplified to ""

FTP111

Find int() which can be simplified to 0

FTP112

Find float() which can be simplified to 0.0

FTP113

Find bool() which can be simplified to False

FTP114

Find bytes() which can be simplified to b""

FTP115

Find invisible unicode characters in source code

FTP116

Find named expressions (walrus operator :=) in assert statements

FTP117

Find functions calling warnings.warn but which are also decorated with warnings.deprecated or typing_extensions.deprecated

FTP118

Find functions calling warnings.warn but which could use warnings.deprecated or typing_extensions.deprecated

FTP119

Checks for unsorted __slots__ attributes on any level. The check is only done if the type is a list, tuple or set during parsing. Only items which are strings are used in the sort check; all others are ignored.

FTP120

Find assignments to __slots__ outside of a class. The assignment can be wrapped into constructs like an if but the first container needs to be a class and not a function or module

FTP121

Find calls of soft-deprecated os functions which should be replaced with subprocess calls like os.popen or os.spawnv

FTP122

Find methods decorated with both classmethod and property. Through the different python versions the behavior is unstable and should be avoided

FTP123

Finds usage of typing.Generator where the last argument in the subscript is None, because with PEP696 these can be omitted. The check is only active if

  • running python 3.13+
  • a from __future__ import annotations import is present in the module
  • the current code is inside a typing.TYPE_CHECKING block

Also, the check will only consider type annotations (to prevent invalid syntax) if at least one of the following conditions is true:

  • python 3.12 or below is used
  • the code is not inside a typing.TYPE_CHECKING block

FTP124

Find assignments to __all__ on non-module level, e.g. in classes or functions

FTP200

Find calls of flask.abort and werkzeug.exceptions.abort. Instead of calling this helper function raise the appropriate exception directly

FTP220

Find usage of requests.codes which should be replaced with http.HTTPStatus