modernize-annotations
FormattingRewrites Optional[T], Union[X, Y], and the typing generics to the T | None, X | Y, and builtin forms the target runtime supports.
The formatting rules rewrite the small details of a statement once its layout is settled, each one changing a token, a line, or a spelling rather than the construct around it. Every rewrite is narrower than a layout rule and more pervasive than an ordering rule, tidying what the eye reads without moving the structure it reads. The rules whose output depends on the runtime read target-version, so a rewrite is written only where the Python version a project ships to accepts it.
Rewrites Optional[T], Union[X, Y], and the typing generics to the T | None, X | Y, and builtin forms the target runtime supports.
Puts one space after a comment's hash run and at least two spaces between code and a trailing comment.
Rewrites a comparison to state its check directly, using is against None, putting the variable side first, and folding a leading not into its operator.
Rewrites every string and numeric literal to one spelling of quote character, string prefix, and numeric case.
Converts printf-style % interpolation and str.format() calls to f-strings wherever both forms render the same text.
Removes an import that binds a name nothing references or repeats a binding an earlier import already made, and reports the unreferenced one in a package __init__.py instead of removing it.
Removes a trailing backslash and rejoins its statement, adding parentheses where the joined line would overflow the budget.
Removes an explicit object base and the empty parentheses on a class header with no bases.
Removes the class and instance arguments from a super(C, self) call, leaving the bare super() the interpreter resolves on its own.
Removes a collection constructor wrapped around a literal, comprehension, or generator that already builds that collection, and replaces a comprehension that copies its input unchanged with the constructor call.
Sets the blank-line count between module-level definitions, class members, import groups, and the __main__ guard to PEP 8's canonical values.
Removes a bare -> None return annotation, since an omitted one already reads as returning nothing.
Removes the trailing comma from a collection, signature, call, class base list, or type-parameter list, leaving tuples alone.
For enabling or disabling any of these rules, see the Configuration reference. For the pipeline order they run in, see the Pipeline Order reference.