That's a very expensive sentinel though. Classes are notoriously heavy objects. On Tue, Nov 24, 2020 at 7:17 PM David Foster <davidfstr@gmail.com> wrote:
I recently ran across some Django code that has an interesting solution for typing a sentinel object: It uses a *type* object as a sentinel rather than just an `object()`:
# django/db/models/fields/__init__.py
class NOT_PROVIDED: pass
class Field(RegisterLookupMixin): def __init__(self, ..., default=NOT_PROVIDED, ...): ...
Presumably the type of the `default` parameter could then be written as:
Union[Type[NOT_PROVIDED], Any]
Not exactly direct, but may work.
-- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: guido@python.org
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>