gh-104050: Argument clinic: complete type annotations (#107399)

This commit is contained in:
Alex Waygood 2023-07-28 21:27:21 +01:00 committed by GitHub
parent c0b81c4b54
commit 55ed85e49c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

@ -2290,8 +2290,9 @@ impl_definition block
return printer.f.getvalue()
def _module_and_class(self, fields):
def _module_and_class(
self, fields: Iterable[str]
) -> tuple[Module | Clinic, Class | None]:
"""
fields should be an iterable of field names.
returns a tuple of (module, class).
@ -2299,19 +2300,21 @@ impl_definition block
this function is only ever used to find the parent of where
a new class/module should go.
"""
in_classes = False
parent: Clinic | Module | Class
child: Module | Class | None
module: Clinic | Module
cls: Class | None = None
so_far: list[str] = []
parent = module = self
cls = None
so_far = []
for field in fields:
so_far.append(field)
if not in_classes:
if not isinstance(parent, Class):
child = parent.modules.get(field)
if child:
parent = module = child
continue
in_classes = True
if not hasattr(parent, 'classes'):
return module, cls
child = parent.classes.get(field)
@ -2379,7 +2382,7 @@ class PythonParser:
@dc.dataclass(repr=False)
class Module:
name: str
module: Module | None = None
module: Module | Clinic
def __post_init__(self) -> None:
self.parent = self.module
@ -2394,7 +2397,7 @@ class Module:
@dc.dataclass(repr=False)
class Class:
name: str
module: Module
module: Module | Clinic
cls: Class | None
typedef: str
type_object: str
@ -2522,7 +2525,7 @@ class Function:
parameters: ParamDict = dc.field(default_factory=dict)
_: dc.KW_ONLY
name: str
module: Module
module: Module | Clinic
cls: Class | None
c_basename: str | None
full_name: str
@ -2538,7 +2541,7 @@ class Function:
docstring_only: bool = False
def __post_init__(self) -> None:
self.parent: Class | Module = self.cls or self.module
self.parent = self.cls or self.module
self.self_converter: self_converter | None = None
self.__render_parameters__: list[Parameter] | None = None

View File

@ -1,12 +1,15 @@
[mypy]
files = Tools/clinic/
pretty = True
# make sure clinic can still be run on Python 3.10
python_version = 3.10
pretty = True
enable_error_code = ignore-without-code
disallow_any_generics = True
# be strict...
strict = True
strict_concatenate = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_unused_configs = True
enable_error_code = ignore-without-code,redundant-expr
warn_unreachable = True
files = Tools/clinic/
# ...except for one extra rule we can't enable just yet
warn_return_any = False