Skip to content

Commit 38a5859

Browse files
authored
Complete stubs for pep8-naming (python#13741)
1 parent fb79994 commit 38a5859

File tree

3 files changed

+134
-22
lines changed

3 files changed

+134
-22
lines changed

stubs/pep8-naming/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

stubs/pep8-naming/METADATA.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
version = "0.14.*"
22
upstream_repository = "https://github.com/PyCQA/pep8-naming"
3-
partial_stub = true
4-
5-
[tool.stubtest]
6-
ignore_missing_stub = true
Lines changed: 134 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,148 @@
1+
import argparse
12
import ast
2-
from _typeshed import Incomplete
3-
from argparse import Namespace
4-
from collections.abc import Generator, Iterable
5-
from typing import Any
3+
import optparse
4+
from collections import deque
5+
from collections.abc import Callable, Generator, Iterable, Sequence
6+
from typing import Final, Literal
7+
from typing_extensions import Self
68

7-
__version__: str
9+
__version__: Final[str]
810

9-
CLASS_METHODS: frozenset[str]
10-
METACLASS_BASES: frozenset[str]
11-
METHOD_CONTAINER_NODES: set[ast.AST]
11+
CLASS_METHODS: Final[frozenset[Literal["__new__", "__init_subclass__", "__class_getitem__"]]]
12+
METACLASS_BASES: Final[frozenset[Literal["type", "ABCMeta"]]]
13+
METHOD_CONTAINER_NODES: Final[set[ast.AST]]
14+
FUNC_NODES: Final[tuple[type[ast.FunctionDef], type[ast.AsyncFunctionDef]]]
15+
16+
class _ASTCheckMeta(type):
17+
codes: tuple[str, ...]
18+
all: list[BaseASTCheck]
19+
def __init__(cls, class_name: str, bases: tuple[object, ...], namespace: Iterable[str]) -> None: ...
20+
21+
class BaseASTCheck(metaclass=_ASTCheckMeta):
22+
codes: tuple[str, ...]
23+
all: list[BaseASTCheck]
24+
def err(self, node: ast.AST, code: str, **kwargs: str) -> tuple[int, int, str, Self]: ...
1225

1326
class NamingChecker:
1427
name: str
1528
version: str
16-
visitors: Any
17-
decorator_to_type: Any
29+
visitors: Sequence[BaseASTCheck]
30+
decorator_to_type: dict[str, Literal["classmethod", "staticmethod"]]
1831
ignore_names: frozenset[str]
19-
parents: Any
2032
def __init__(self, tree: ast.AST, filename: str) -> None: ...
2133
@classmethod
22-
def add_options(cls, parser: Any) -> None: ...
34+
def add_options(cls, parser: optparse.OptionParser) -> None: ...
2335
@classmethod
24-
def parse_options(cls, option: Namespace) -> None: ...
25-
def run(self) -> Generator[tuple[int, int, str, type[Any]], None, None]: ...
36+
def parse_options(cls, options: argparse.Namespace) -> None: ...
37+
def run(self) -> Generator[tuple[int, int, str, Self]] | tuple[()]: ...
38+
def visit_tree(self, node: ast.AST, parents: deque[ast.AST]) -> Generator[tuple[int, int, str, Self]]: ...
39+
def visit_node(self, node: ast.AST, parents: Sequence[ast.AST]) -> Generator[tuple[int, int, str, Self]]: ...
2640
def tag_class_functions(self, cls_node: ast.ClassDef) -> None: ...
2741
def set_function_nodes_types(self, nodes: Iterable[ast.AST], ismetaclass: bool, late_decoration: dict[str, str]) -> None: ...
28-
def __getattr__(self, name: str) -> Incomplete: ... # incomplete (other attributes are normally not accessed)
42+
@classmethod
43+
def find_decorator_name(cls, d: ast.Expr) -> str: ...
44+
@staticmethod
45+
def find_global_defs(func_def_node: ast.AST) -> None: ...
46+
47+
class ClassNameCheck(BaseASTCheck):
48+
codes: tuple[Literal["N801"], Literal["N818"]]
49+
N801: str
50+
N818: str
51+
@classmethod
52+
def get_classdef(cls, name: str, parents: Sequence[ast.AST]) -> ast.ClassDef | None: ...
53+
@classmethod
54+
def superclass_names(cls, name: str, parents: Sequence[ast.AST], _names: set[str] | None = None) -> set[str]: ...
55+
def visit_classdef(
56+
self, node: ast.ClassDef, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
57+
) -> Generator[tuple[int, int, str, Self]]: ...
58+
59+
class FunctionNameCheck(BaseASTCheck):
60+
codes: tuple[Literal["N802"], Literal["N807"]]
61+
N802: str
62+
N807: str
63+
@staticmethod
64+
def has_override_decorator(node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool: ...
65+
def visit_functiondef(
66+
self, node: ast.FunctionDef, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
67+
) -> Generator[tuple[int, int, str, Self]]: ...
68+
def visit_asyncfunctiondef(
69+
self, node: ast.AsyncFunctionDef, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
70+
) -> Generator[tuple[int, int, str, Self]]: ...
71+
72+
class FunctionArgNamesCheck(BaseASTCheck):
73+
codes: tuple[Literal["N803"], Literal["N804"], Literal["N805"]]
74+
N803: str
75+
N804: str
76+
N805: str
77+
def visit_functiondef(
78+
self, node: ast.FunctionDef, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
79+
) -> Generator[tuple[int, int, str, Self]]: ...
80+
def visit_asyncfunctiondef(
81+
self, node: ast.AsyncFunctionDef, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
82+
) -> Generator[tuple[int, int, str, Self]]: ...
83+
84+
class ImportAsCheck(BaseASTCheck):
85+
codes: tuple[Literal["N811"], Literal["N812"], Literal["N813"], Literal["N814"], Literal["N817"]]
86+
N811: str
87+
N812: str
88+
N813: str
89+
N814: str
90+
N817: str
91+
def visit_importfrom(
92+
self, node: ast.ImportFrom, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
93+
) -> Generator[tuple[int, int, str, Self]]: ...
94+
def visit_import(
95+
self, node: ast.Import, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
96+
) -> Generator[tuple[int, int, str, Self]]: ...
97+
98+
class VariablesCheck(BaseASTCheck):
99+
codes: tuple[Literal["N806"], Literal["N815"], Literal["N816"]]
100+
N806: str
101+
N815: str
102+
N816: str
103+
@staticmethod
104+
def is_namedtupe(node_value: ast.AST) -> bool: ...
105+
def visit_assign(
106+
self, node: ast.Assign, parents: Sequence[ast.AST], ignore: Iterable[str] | None = None
107+
) -> Generator[tuple[int, int, str, Self]]: ...
108+
def visit_namedexpr(
109+
self, node: ast.NamedExpr, parents: Sequence[ast.AST], ignore: Iterable[str]
110+
) -> Generator[tuple[int, int, str, Self]]: ...
111+
def visit_annassign(
112+
self, node: ast.AnnAssign, parents: Sequence[ast.AST], ignore: Iterable[str]
113+
) -> Generator[tuple[int, int, str, Self]]: ...
114+
def visit_with(
115+
self, node: ast.With, parents: Sequence[ast.AST], ignore: Iterable[str]
116+
) -> Generator[tuple[int, int, str, Self]]: ...
117+
def visit_asyncwith(
118+
self, node: ast.AsyncWith, parents: Sequence[ast.AST], ignore: Iterable[str]
119+
) -> Generator[tuple[int, int, str, Self]]: ...
120+
def visit_for(
121+
self, node: ast.For, parents: Sequence[ast.AST], ignore: Iterable[str]
122+
) -> Generator[tuple[int, int, str, Self]]: ...
123+
def visit_asyncfor(
124+
self, node: ast.AsyncFor, parents: Sequence[ast.AST], ignore: Iterable[str]
125+
) -> Generator[tuple[int, int, str, Self]]: ...
126+
def visit_excepthandler(
127+
self, node: ast.ExceptHandler, parents: Sequence[ast.AST], ignore: Iterable[str]
128+
) -> Generator[tuple[int, int, str, Self]]: ...
129+
def visit_generatorexp(
130+
self, node: ast.GeneratorExp, parents: Sequence[ast.AST], ignore: Iterable[str]
131+
) -> Generator[tuple[int, int, str, Self]]: ...
132+
def visit_listcomp(
133+
self, node: ast.ListComp, parents: Sequence[ast.AST], ignore: Iterable[str]
134+
) -> Generator[tuple[int, int, str, Self]]: ...
135+
def visit_dictcomp(
136+
self, node: ast.DictComp, parents: Sequence[ast.AST], ignore: Iterable[str]
137+
) -> Generator[tuple[int, int, str, Self]]: ...
138+
def visit_setcomp(
139+
self, node: ast.SetComp, parents: Sequence[ast.AST], ignore: Iterable[str]
140+
) -> Generator[tuple[int, int, str, Self]]: ...
141+
@staticmethod
142+
def global_variable_check(name: str) -> Literal["N816"] | None: ...
143+
@staticmethod
144+
def class_variable_check(name: str) -> Literal["N815"] | None: ...
145+
@staticmethod
146+
def function_variable_check(func: Callable[..., object], var_name: str) -> Literal["N806"] | None: ...
29147

30-
def __getattr__(name: str) -> Incomplete: ... # incomplete (other attributes are normally not accessed)
148+
def is_mixed_case(name: str) -> bool: ...

0 commit comments

Comments
 (0)