[lint] simplify lint config for flake8-annotations (#12073)

Co-authored-by: daniel.eades <daniel.eades@seebyte.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
danieleades 2024-03-14 10:37:15 +00:00 committed by GitHub
parent 92380e60d1
commit d6f49f9c09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 49 additions and 54 deletions

View File

@ -15,6 +15,8 @@ exclude = [
"doc/usage/extensions/example*.py",
]
ignore = [
# flake8-annotations
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `{name}`
# pycodestyle
"E741", # Ambiguous variable name: `{name}`
# pyflakes
@ -31,16 +33,7 @@ select = [
# NOT YET USED
# airflow ('AIR')
# Airflow is not used in Sphinx
# flake8-annotations ('ANN')
"ANN001", # Missing type annotation for function argument `{name}`
"ANN002", # Missing type annotation for `*{name}`
"ANN003", # Missing type annotation for `**{name}`
"ANN201", # Missing return type annotation for public function `{name}`
"ANN202", # Missing return type annotation for private function `{name}`
# "ANN204", # Missing return type annotation for special method `{name}`
"ANN205", # Missing return type annotation for staticmethod `{name}`
"ANN206", # Missing return type annotation for classmethod `{name}`
# "ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `{name}`
"ANN", # flake8-annotations ('ANN')
# flake8-unused-arguments ('ARG')
"ARG004", # Unused static method argument: `{name}`
# flake8-async ('ASYNC')

View File

@ -332,7 +332,7 @@ class desc_sig_element(nodes.inline, _desc_classes_injector):
super().__init__(rawsource, text, *children, **attributes)
self['classes'].extend(self.classes)
def __init_subclass__(cls, *, _sig_element: bool = False, **kwargs: Any):
def __init_subclass__(cls, *, _sig_element: bool = False, **kwargs: Any) -> None:
super().__init_subclass__(**kwargs)
if _sig_element:
# add the class to the SIG_ELEMENTS set if asked

View File

@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)
class Message:
"""An entry of translatable message."""
def __init__(self, text: str, locations: list[tuple[str, int]], uuids: list[str]):
def __init__(self, text: str, locations: list[tuple[str, int]], uuids: list[str]) -> None:
self.text = text
self.locations = locations
self.uuids = uuids

View File

@ -363,7 +363,7 @@ class Config:
if name not in self._options:
logger.warning(__('unknown config value %r in override, ignoring'), name)
def __repr__(self):
def __repr__(self) -> str:
values = []
for opt_name in self._options:
try:

View File

@ -247,7 +247,7 @@ class ASTStringLiteral(ASTLiteral):
class ASTIdExpression(ASTExpression):
def __init__(self, name: ASTNestedName):
def __init__(self, name: ASTNestedName) -> None:
# note: this class is basically to cast a nested name as an expression
self.name = name
@ -344,7 +344,7 @@ class ASTPostfixMemberOfPointer(ASTPostfixOp):
class ASTPostfixExpr(ASTExpression):
def __init__(self, prefix: ASTExpression, postFixes: list[ASTPostfixOp]):
def __init__(self, prefix: ASTExpression, postFixes: list[ASTPostfixOp]) -> None:
self.prefix = prefix
self.postFixes = postFixes
@ -362,7 +362,7 @@ class ASTPostfixExpr(ASTExpression):
################################################################################
class ASTUnaryOpExpr(ASTExpression):
def __init__(self, op: str, expr: ASTExpression):
def __init__(self, op: str, expr: ASTExpression) -> None:
self.op = op
self.expr = expr
@ -398,7 +398,7 @@ class ASTSizeofType(ASTExpression):
class ASTSizeofExpr(ASTExpression):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -412,7 +412,7 @@ class ASTSizeofExpr(ASTExpression):
class ASTAlignofExpr(ASTExpression):
def __init__(self, typ: ASTType):
def __init__(self, typ: ASTType) -> None:
self.typ = typ
def _stringify(self, transform: StringifyTransform) -> str:
@ -430,7 +430,7 @@ class ASTAlignofExpr(ASTExpression):
################################################################################
class ASTCastExpr(ASTExpression):
def __init__(self, typ: ASTType, expr: ASTExpression):
def __init__(self, typ: ASTType, expr: ASTExpression) -> None:
self.typ = typ
self.expr = expr
@ -450,7 +450,7 @@ class ASTCastExpr(ASTExpression):
class ASTBinOpExpr(ASTBase):
def __init__(self, exprs: list[ASTExpression], ops: list[str]):
def __init__(self, exprs: list[ASTExpression], ops: list[str]) -> None:
assert len(exprs) > 0
assert len(exprs) == len(ops) + 1
self.exprs = exprs
@ -481,7 +481,7 @@ class ASTBinOpExpr(ASTBase):
class ASTAssignmentExpr(ASTExpression):
def __init__(self, exprs: list[ASTExpression], ops: list[str]):
def __init__(self, exprs: list[ASTExpression], ops: list[str]) -> None:
assert len(exprs) > 0
assert len(exprs) == len(ops) + 1
self.exprs = exprs
@ -512,7 +512,7 @@ class ASTAssignmentExpr(ASTExpression):
class ASTFallbackExpr(ASTExpression):
def __init__(self, expr: str):
def __init__(self, expr: str) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -784,7 +784,7 @@ class ASTDeclSpecs(ASTBase):
class ASTArray(ASTBase):
def __init__(self, static: bool, const: bool, volatile: bool, restrict: bool,
vla: bool, size: ASTExpression):
vla: bool, size: ASTExpression) -> None:
self.static = static
self.const = const
self.volatile = volatile
@ -895,7 +895,7 @@ class ASTDeclaratorNameParam(ASTDeclarator):
class ASTDeclaratorNameBitField(ASTDeclarator):
def __init__(self, declId: ASTNestedName, size: ASTExpression):
def __init__(self, declId: ASTNestedName, size: ASTExpression) -> None:
self.declId = declId
self.size = size

View File

@ -13,6 +13,8 @@ from sphinx.util import logging
if TYPE_CHECKING:
from collections.abc import Generator, Iterator
from typing_extensions import Self
from sphinx.environment import BuildEnvironment
logger = logging.getLogger(__name__)
@ -52,7 +54,7 @@ class Symbol:
debug_lookup = False
debug_show_tree = False
def __copy__(self):
def __copy__(self) -> Self:
raise AssertionError # shouldn't happen
def __deepcopy__(self, memo: Any) -> Symbol:

View File

@ -411,7 +411,7 @@ class ASTCharLiteral(ASTLiteral):
class ASTUserDefinedLiteral(ASTLiteral):
def __init__(self, literal: ASTLiteral, ident: ASTIdentifier):
def __init__(self, literal: ASTLiteral, ident: ASTIdentifier) -> None:
self.literal = literal
self.ident = ident
@ -505,7 +505,7 @@ class ASTFoldExpr(ASTExpression):
class ASTParenExpr(ASTExpression):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -522,7 +522,7 @@ class ASTParenExpr(ASTExpression):
class ASTIdExpression(ASTExpression):
def __init__(self, name: ASTNestedName):
def __init__(self, name: ASTNestedName) -> None:
# note: this class is basically to cast a nested name as an expression
self.name = name
@ -550,7 +550,7 @@ class ASTPostfixOp(ASTBase):
class ASTPostfixArray(ASTPostfixOp):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -567,7 +567,7 @@ class ASTPostfixArray(ASTPostfixOp):
class ASTPostfixMember(ASTPostfixOp):
def __init__(self, name: ASTNestedName):
def __init__(self, name: ASTNestedName) -> None:
self.name = name
def _stringify(self, transform: StringifyTransform) -> str:
@ -583,7 +583,7 @@ class ASTPostfixMember(ASTPostfixOp):
class ASTPostfixMemberOfPointer(ASTPostfixOp):
def __init__(self, name: ASTNestedName):
def __init__(self, name: ASTNestedName) -> None:
self.name = name
def _stringify(self, transform: StringifyTransform) -> str:
@ -643,7 +643,7 @@ class ASTPostfixCallExpr(ASTPostfixOp):
class ASTPostfixExpr(ASTExpression):
def __init__(self, prefix: ASTType, postFixes: list[ASTPostfixOp]):
def __init__(self, prefix: ASTType, postFixes: list[ASTPostfixOp]) -> None:
self.prefix = prefix
self.postFixes = postFixes
@ -664,7 +664,7 @@ class ASTPostfixExpr(ASTExpression):
class ASTExplicitCast(ASTExpression):
def __init__(self, cast: str, typ: ASTType, expr: ASTExpression):
def __init__(self, cast: str, typ: ASTType, expr: ASTExpression) -> None:
assert cast in _id_explicit_cast
self.cast = cast
self.typ = typ
@ -696,7 +696,7 @@ class ASTExplicitCast(ASTExpression):
class ASTTypeId(ASTExpression):
def __init__(self, typeOrExpr: ASTType | ASTExpression, isType: bool):
def __init__(self, typeOrExpr: ASTType | ASTExpression, isType: bool) -> None:
self.typeOrExpr = typeOrExpr
self.isType = isType
@ -719,7 +719,7 @@ class ASTTypeId(ASTExpression):
################################################################################
class ASTUnaryOpExpr(ASTExpression):
def __init__(self, op: str, expr: ASTExpression):
def __init__(self, op: str, expr: ASTExpression) -> None:
self.op = op
self.expr = expr
@ -743,7 +743,7 @@ class ASTUnaryOpExpr(ASTExpression):
class ASTSizeofParamPack(ASTExpression):
def __init__(self, identifier: ASTIdentifier):
def __init__(self, identifier: ASTIdentifier) -> None:
self.identifier = identifier
def _stringify(self, transform: StringifyTransform) -> str:
@ -763,7 +763,7 @@ class ASTSizeofParamPack(ASTExpression):
class ASTSizeofType(ASTExpression):
def __init__(self, typ: ASTType):
def __init__(self, typ: ASTType) -> None:
self.typ = typ
def _stringify(self, transform: StringifyTransform) -> str:
@ -781,7 +781,7 @@ class ASTSizeofType(ASTExpression):
class ASTSizeofExpr(ASTExpression):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -798,7 +798,7 @@ class ASTSizeofExpr(ASTExpression):
class ASTAlignofExpr(ASTExpression):
def __init__(self, typ: ASTType):
def __init__(self, typ: ASTType) -> None:
self.typ = typ
def _stringify(self, transform: StringifyTransform) -> str:
@ -816,7 +816,7 @@ class ASTAlignofExpr(ASTExpression):
class ASTNoexceptExpr(ASTExpression):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -883,7 +883,7 @@ class ASTNewExpr(ASTExpression):
class ASTDeleteExpr(ASTExpression):
def __init__(self, rooted: bool, array: bool, expr: ASTExpression):
def __init__(self, rooted: bool, array: bool, expr: ASTExpression) -> None:
self.rooted = rooted
self.array = array
self.expr = expr
@ -921,7 +921,7 @@ class ASTDeleteExpr(ASTExpression):
################################################################################
class ASTCastExpr(ASTExpression):
def __init__(self, typ: ASTType, expr: ASTExpression):
def __init__(self, typ: ASTType, expr: ASTExpression) -> None:
self.typ = typ
self.expr = expr
@ -944,7 +944,7 @@ class ASTCastExpr(ASTExpression):
class ASTBinOpExpr(ASTExpression):
def __init__(self, exprs: list[ASTExpression], ops: list[str]):
def __init__(self, exprs: list[ASTExpression], ops: list[str]) -> None:
assert len(exprs) > 0
assert len(exprs) == len(ops) + 1
self.exprs = exprs
@ -985,7 +985,7 @@ class ASTBinOpExpr(ASTExpression):
class ASTConditionalExpr(ASTExpression):
def __init__(self, ifExpr: ASTExpression, thenExpr: ASTExpression,
elseExpr: ASTExpression):
elseExpr: ASTExpression) -> None:
self.ifExpr = ifExpr
self.thenExpr = thenExpr
self.elseExpr = elseExpr
@ -1054,7 +1054,7 @@ class ASTBracedInitList(ASTBase):
class ASTAssignmentExpr(ASTExpression):
def __init__(self, leftExpr: ASTExpression, op: str,
rightExpr: ASTExpression | ASTBracedInitList):
rightExpr: ASTExpression | ASTBracedInitList) -> None:
self.leftExpr = leftExpr
self.op = op
self.rightExpr = rightExpr
@ -1089,7 +1089,7 @@ class ASTAssignmentExpr(ASTExpression):
class ASTCommaExpr(ASTExpression):
def __init__(self, exprs: list[ASTExpression]):
def __init__(self, exprs: list[ASTExpression]) -> None:
assert len(exprs) > 0
self.exprs = exprs
@ -1115,7 +1115,7 @@ class ASTCommaExpr(ASTExpression):
class ASTFallbackExpr(ASTExpression):
def __init__(self, expr: str):
def __init__(self, expr: str) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -1411,7 +1411,7 @@ class ASTTrailingTypeSpecDecltypeAuto(ASTTrailingTypeSpec):
class ASTTrailingTypeSpecDecltype(ASTTrailingTypeSpec):
def __init__(self, expr: ASTExpression):
def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -1509,7 +1509,7 @@ class ASTFunctionParameter(ASTBase):
class ASTNoexceptSpec(ASTBase):
def __init__(self, expr: ASTExpression | None):
def __init__(self, expr: ASTExpression | None) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@ -1870,7 +1870,7 @@ class ASTDeclSpecs(ASTBase):
################################################################################
class ASTArray(ASTBase):
def __init__(self, size: ASTExpression):
def __init__(self, size: ASTExpression) -> None:
self.size = size
def _stringify(self, transform: StringifyTransform) -> str:
@ -2033,7 +2033,7 @@ class ASTDeclaratorNameParamQual(ASTDeclarator):
class ASTDeclaratorNameBitField(ASTDeclarator):
def __init__(self, declId: ASTNestedName, size: ASTExpression):
def __init__(self, declId: ASTNestedName, size: ASTExpression) -> None:
self.declId = declId
self.size = size
@ -2490,7 +2490,7 @@ class ASTDeclaratorParen(ASTDeclarator):
##############################################################################################
class ASTPackExpansionExpr(ASTExpression):
def __init__(self, expr: ASTExpression | ASTBracedInitList):
def __init__(self, expr: ASTExpression | ASTBracedInitList) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:

View File

@ -146,7 +146,7 @@ class BuildEnvironment:
# --------- ENVIRONMENT INITIALIZATION -------------------------------------
def __init__(self, app: Sphinx):
def __init__(self, app: Sphinx) -> None:
self.app: Sphinx = app
self.doctreedir: Path = app.doctreedir
self.srcdir: Path = app.srcdir

View File

@ -605,7 +605,7 @@ class ImportExceptionGroup(Exception):
It contains an error messages and a list of exceptions as its arguments.
"""
def __init__(self, message: str | None, exceptions: Sequence[BaseException]):
def __init__(self, message: str | None, exceptions: Sequence[BaseException]) -> None:
super().__init__(message)
self.exceptions = list(exceptions)