change standard repr to ClassName

This commit is contained in:
Luciano Ramalho
2021-05-23 22:19:15 -03:00
parent f248baf418
commit be7a67c93e
2 changed files with 5 additions and 6 deletions

View File

@@ -2,12 +2,12 @@
>>> class Missing(Sentinel): pass >>> class Missing(Sentinel): pass
>>> Missing >>> Missing
<Missing> Missing
>>> class CustomRepr(Sentinel): >>> class CustomRepr(Sentinel):
... repr = '*** sentinel ***' ... repr = '<CustomRepr>'
... ...
>>> CustomRepr >>> CustomRepr
*** sentinel *** <CustomRepr>
""" """
@@ -16,9 +16,8 @@ class SentinelMeta(type):
try: try:
return cls.repr return cls.repr
except AttributeError: except AttributeError:
return f'<{cls.__name__}>' return cls.__name__
class Sentinel(metaclass=SentinelMeta): class Sentinel(metaclass=SentinelMeta):
def __new__(cls): def __new__(cls):
return cls return cls

View File

@@ -8,7 +8,7 @@ class SentinelCustomRepr(Sentinel):
def test_repr(): def test_repr():
assert repr(PlainSentinel) == '<PlainSentinel>' assert repr(PlainSentinel) == 'PlainSentinel'
def test_pickle(): def test_pickle():