Open DetachHead opened 1 week ago
Must apply to print
as well, I suggest we action HelpfulString
and UnhelpfulString
in basedtyping.
You must also consider __repr__
and None
To clarify:
if value does not define a
__str__
Does this mean if both the __str__
and __repr__
we would get is the same as object.__str__
and object.__repr__
?
It wouldn't be nice to have to define this in every subclass of a class where we've defined __str__
def __str__(self) -> str:
return super().__str__()
the motivation is to prevent non-user friendly strings from being presented to the user. i got the idea from this eslint rule.
users who don't like the rule will be able to disable it if they want
It wouldn't be nice to have to define this in every subclass of a class where we've defined
__str__
it would work like this
class A:
pass
class B(A):
def __str__(self):
return "something"
class C(B):
pass
f"{object()}" # warning: reportUnhelpfulString
f"{A()}" # warning: reportUnhelpfulString
f"{B()}" # no report
f"{C()}" # no report
If you inherit from a helpful string, then that counts as a helpful string
usually this results in a useless string representation of an object being displayed to the user (eg.
<Foo object at 0xasdfasdf>
)