-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Closed as not planned
Copy link
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
For
from __future__ import annotations
from typing import NamedTuple
class Biz(NamedTuple):
our_final_destination: list[Foo]
class Bar(NamedTuple):
even_longer_attribute_name_presumably: Biz
class Foo(NamedTuple):
very_long_attribute_name: Bar
foo = Foo(Bar(Biz(Bar(dest := []))))
dest.append(foo)
print(foo)
Before decorating:
Foo(very_long_attribute_name=Bar(even_longer_attribute_name_presumably=Biz(our_final_destination=Bar(even_longer_attribute_name_presumably=[Foo(very_long_attribute_name=Bar(even_longer_attribute_name_presumably=Biz(our_final_destination=Bar(even_longer_attribute_name_presumably=[...]))))]))))
after decorating:
Foo(very_long_attribute_name=Bar(even_longer_attribute_name_presumably=Biz(our_final_destination=Bar(even_longer_attribute_name_presumably=[...]))))
(Note that if our_final_destination
pointed to Foo
, e.g. via a mutable object that didn't have recursive repr support but included foo
in its repr, printing foo
would fail with a recursion limit excess. It's not a bug of CPython by any means though.)
The decorator is already available in the module as _recursive_repr
, so it's just a matter of application.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-featureA feature request or enhancementA feature request or enhancement