Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2290,28 +2290,31 @@ def parse(self, input: str) -> str:

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).
the module object could actually be self (a clinic object).
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)
Expand Down Expand Up @@ -2379,7 +2382,7 @@ def parse(self, block: Block) -> None:
@dc.dataclass(repr=False)
class Module:
name: str
module: Module | None = None
module: Module | Clinic

def __post_init__(self) -> None:
self.parent = self.module
Expand All @@ -2394,7 +2397,7 @@ def __repr__(self) -> str:
@dc.dataclass(repr=False)
class Class:
name: str
module: Module
module: Module | Clinic
cls: Class | None
typedef: str
type_object: str
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
17 changes: 10 additions & 7 deletions Tools/clinic/mypy.ini
Original file line number Diff line number Diff line change
@@ -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
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved