diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-08-05 20:58:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:58:38 (GMT) |
commit | 6996b406bcf9f6d85a59e539c743ef9126c3cc5d (patch) | |
tree | d2e8bdbc9656016dbcc4b389976aae519f2baa17 /Tools/clinic | |
parent | 4a5b4221e381c541f3f73537b7b87580d100158b (diff) | |
download | cpython-6996b406bcf9f6d85a59e539c743ef9126c3cc5d.zip cpython-6996b406bcf9f6d85a59e539c743ef9126c3cc5d.tar.gz cpython-6996b406bcf9f6d85a59e539c743ef9126c3cc5d.tar.bz2 |
gh-104683: Improve consistency and test coverage of argument-clinic `__repr__` functions (#107667)
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-x | Tools/clinic/clinic.py | 20 | ||||
-rw-r--r-- | Tools/clinic/cpp.py | 7 |
2 files changed, 17 insertions, 10 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7fbae1e..423cdfb 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1728,8 +1728,12 @@ class Block: if len(s) > 30: return s[:26] + "..." + s[0] return s - return "".join(( - "<Block ", dsl_name, " input=", summarize(self.input), " output=", summarize(self.output), ">")) + parts = ( + repr(dsl_name), + f"input={summarize(self.input)}", + f"output={summarize(self.output)}" + ) + return f"<clinic.Block {' '.join(parts)}>" class BlockParser: @@ -2037,10 +2041,10 @@ class Destination: def __repr__(self) -> str: if self.type == 'file': - file_repr = " " + repr(self.filename) + type_repr = f"type='file' file={self.filename!r}" else: - file_repr = '' - return "".join(("<Destination ", self.name, " ", self.type, file_repr, ">")) + type_repr = f"type={self.type!r}" + return f"<clinic.Destination {self.name!r} {type_repr}>" def clear(self) -> None: if self.type != 'buffer': @@ -2500,7 +2504,7 @@ class FunctionKind(enum.Enum): return self in {FunctionKind.METHOD_INIT, FunctionKind.METHOD_NEW} def __repr__(self) -> str: - return f"<FunctionKind.{self.name}>" + return f"<clinic.FunctionKind.{self.name}>" INVALID: Final = FunctionKind.INVALID @@ -2577,7 +2581,7 @@ class Function: return '|'.join(flags) def __repr__(self) -> str: - return '<clinic.Function ' + self.name + '>' + return f'<clinic.Function {self.name!r}>' def copy(self, **overrides: Any) -> Function: f = dc.replace(self, **overrides) @@ -2605,7 +2609,7 @@ class Parameter: right_bracket_count: int = dc.field(init=False, default=0) def __repr__(self) -> str: - return '<clinic.Parameter ' + self.name + '>' + return f'<clinic.Parameter {self.name!r}>' def is_keyword_only(self) -> bool: return self.kind == inspect.Parameter.KEYWORD_ONLY diff --git a/Tools/clinic/cpp.py b/Tools/clinic/cpp.py index 21a1b02..8761051 100644 --- a/Tools/clinic/cpp.py +++ b/Tools/clinic/cpp.py @@ -43,9 +43,12 @@ class Monitor: self.line_number = 0 def __repr__(self) -> str: - return ( - f"<Monitor {id(self)} line={self.line_number} condition={self.condition()!r}>" + parts = ( + str(id(self)), + f"line={self.line_number}", + f"condition={self.condition()!r}" ) + return f"<clinic.Monitor {' '.join(parts)}>" def status(self) -> str: return str(self.line_number).rjust(4) + ": " + self.condition() |