This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author taleinat
Recipients eric.smith, iritkatriel, taleinat, zach.ware
Date 2021-05-13.21:09:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620940172.5.0.0826904867226.issue44123@roundup.psfhosted.org>
In-reply-to
Content
... 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'>
History
Date User Action Args
2021-05-13 21:09:32taleinatsetrecipients: + taleinat, eric.smith, zach.ware, iritkatriel
2021-05-13 21:09:32taleinatsetmessageid: <1620940172.5.0.0826904867226.issue44123@roundup.psfhosted.org>
2021-05-13 21:09:32taleinatlinkissue44123 messages
2021-05-13 21:09:32taleinatcreate