Message393606
... and they can be given excellent reprs by using a meta-class:
class Sentinel(type):
@classmethod
def __prepare__(cls, name, bases, **kwds):
d = super().__prepare__(name, bases, **kwds)
def __new__(cls_, *args, **kwargs):
raise TypeError(
f'{cls_!r} is a sentinel and cannot be instantiated')
d.update(__new__=__new__)
return d
def __repr__(cls):
return f'{cls.__module__}.{cls.__qualname__}'
class MISSING(metaclass=Sentinel): pass
This also has another nice benefit:
>>> type(MISSING)
<class 'sentinels.Sentinel'> |
|
Date |
User |
Action |
Args |
2021-05-13 21:09:32 | taleinat | set | recipients:
+ taleinat, eric.smith, zach.ware, iritkatriel |
2021-05-13 21:09:32 | taleinat | set | messageid: <1620940172.5.0.0826904867226.issue44123@roundup.psfhosted.org> |
2021-05-13 21:09:32 | taleinat | link | issue44123 messages |
2021-05-13 21:09:32 | taleinat | create | |
|