summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-05-18 22:57:26 (GMT)
committerGitHub <noreply@github.com>2023-05-18 22:57:26 (GMT)
commit94c8edabd3d6c8739aaae9b1cb0be822c754c742 (patch)
tree8103f4476203d2384d343469cba4e846b8ff7e3b /Tools
parent86ee49f469b84e4b746526a00d8191d0e374a268 (diff)
downloadcpython-94c8edabd3d6c8739aaae9b1cb0be822c754c742.zip
cpython-94c8edabd3d6c8739aaae9b1cb0be822c754c742.tar.gz
cpython-94c8edabd3d6c8739aaae9b1cb0be822c754c742.tar.bz2
gh-104050: Add more type annotations to Argument Clinic (#104628)
Annotate the following: - methods of class Class - methods of class Module - methods of class PythonParser - function compute_checksum() - function parse_file() - global variable unsupported_special_methods
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py53
1 files changed, 39 insertions, 14 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 42aac7e..3d4961e 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2229,7 +2229,12 @@ impl_definition block
return module, cls
-def parse_file(filename, *, verify=True, output=None):
+def parse_file(
+ filename: str,
+ *,
+ verify: bool = True,
+ output: str | None = None
+) -> None:
if not output:
output = filename
@@ -2261,7 +2266,10 @@ def parse_file(filename, *, verify=True, output=None):
write_file(fn, data)
-def compute_checksum(input, length=None):
+def compute_checksum(
+ input: str | None,
+ length: int | None = None
+) -> str:
input = input or ''
s = hashlib.sha1(input.encode('utf-8')).hexdigest()
if length:
@@ -2272,30 +2280,46 @@ def compute_checksum(input, length=None):
class PythonParser:
- def __init__(self, clinic):
+ def __init__(self, clinic: Clinic) -> None:
pass
- def parse(self, block):
+ def parse(self, block: Block) -> None:
s = io.StringIO()
with OverrideStdioWith(s):
exec(block.input)
block.output = s.getvalue()
+ModuleDict = dict[str, "Module"]
+
class Module:
- def __init__(self, name, module=None):
+ def __init__(
+ self,
+ name: str,
+ module = None
+ ) -> None:
self.name = name
self.module = self.parent = module
- self.modules = collections.OrderedDict()
- self.classes = collections.OrderedDict()
- self.functions = []
+ self.modules: ModuleDict = collections.OrderedDict()
+ self.classes: ClassDict = collections.OrderedDict()
+ self.functions: list[Function] = []
- def __repr__(self):
+ def __repr__(self) -> str:
return "<clinic.Module " + repr(self.name) + " at " + str(id(self)) + ">"
+
+ClassDict = dict[str, "Class"]
+
class Class:
- def __init__(self, name, module=None, cls=None, typedef=None, type_object=None):
+ def __init__(
+ self,
+ name: str,
+ module: Module | None = None,
+ cls = None,
+ typedef: str | None = None,
+ type_object: str | None = None
+ ) -> None:
self.name = name
self.module = module
self.cls = cls
@@ -2303,13 +2327,14 @@ class Class:
self.type_object = type_object
self.parent = cls or module
- self.classes = collections.OrderedDict()
- self.functions = []
+ self.classes: ClassDict = collections.OrderedDict()
+ self.functions: list[Function] = []
- def __repr__(self):
+ def __repr__(self) -> str:
return "<clinic.Class " + repr(self.name) + " at " + str(id(self)) + ">"
-unsupported_special_methods = set("""
+
+unsupported_special_methods: set[str] = set("""
__abs__
__add__