change standard repr to ClassName
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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():
|
||||||
|
|||||||
Reference in New Issue
Block a user