summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xTools/clinic/clinic.py25
-rw-r--r--Tools/clinic/mypy.ini17
2 files changed, 24 insertions, 18 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 39c6de3..6bfa6d0 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -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
diff --git a/Tools/clinic/mypy.ini b/Tools/clinic/mypy.ini
index 672911d..4aa65a5 100644
--- a/Tools/clinic/mypy.ini
+++ b/Tools/clinic/mypy.ini
@@ -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