From 9165833d5ca42b50ecf7a53ac90c9c647e24e93e Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 4 Aug 2025 02:25:08 +0000 Subject: [PATCH 1/2] feat: `__repr__` method for RefExpr and NameExpr The addition of these 2 simple reprs was helpful for me for debugging a compiler issue locally --- mypy/nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mypy/nodes.py b/mypy/nodes.py index 011e4e703a0c..8c7c0eedcfb5 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -1914,6 +1914,9 @@ def __init__(self) -> None: # And same for TypeIs self.type_is: mypy.types.Type | None = None + def __repr__(self) -> str: + return f"<{type(self).__name__} fullname={self.fullname} of {self.node} object at {hex(id(self))}>" + @property def fullname(self) -> str: return self._fullname @@ -1939,6 +1942,9 @@ def __init__(self, name: str) -> None: # Is this a l.h.s. of a special form assignment like typed dict or type variable? self.is_special_form = False + def __repr__(self) -> str: + return f"<{type(self).__name__} fullname={self.fullname} special_form={self.is_special_form} of {self.node} object at {hex(id(self))}>" + def accept(self, visitor: ExpressionVisitor[T]) -> T: return visitor.visit_name_expr(self) From c87b2b0cc698ccd9ccf63cbe34e977a95b66e6a9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 4 Aug 2025 02:25:08 +0000 Subject: [PATCH 2/2] Update nodes.py --- mypy/nodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/nodes.py b/mypy/nodes.py index 8c7c0eedcfb5..613c60806b0e 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -1915,7 +1915,7 @@ def __init__(self) -> None: self.type_is: mypy.types.Type | None = None def __repr__(self) -> str: - return f"<{type(self).__name__} fullname={self.fullname} of {self.node} object at {hex(id(self))}>" + return f"<{type(self).__name__} fullname={self.fullname} type={self.type_is} of {self.node} object at {hex(id(self))}>" @property def fullname(self) -> str: @@ -1943,7 +1943,7 @@ def __init__(self, name: str) -> None: self.is_special_form = False def __repr__(self) -> str: - return f"<{type(self).__name__} fullname={self.fullname} special_form={self.is_special_form} of {self.node} object at {hex(id(self))}>" + return f"<{type(self).__name__} fullname={self.fullname} type={self.type_is} special_form={self.is_special_form} of {self.node} object at {hex(id(self))}>" def accept(self, visitor: ExpressionVisitor[T]) -> T: return visitor.visit_name_expr(self)