PEP-661 was accepted, but it is implemented a little differently than our typing_extensions.Sentinel. Let's see how we can make the typing-extensions version better match the version that will be in Python 3.15, while keeping backward compatibility for users who may already be using typing_extensions.Sentinel.
Here are the relevant differences:
- We have
typing_extensions.Sentinel; 3.15 will have builtins.sentinel (lowercase). Let's not worry about the name. On Python 3.15 we'll re-export builtins.sentinel as typing_extensions.Sentinel.
- Our Sentinel is subclassable;
builtins.sentinel will not be. Let's add an __init_subclass__ that emits a DeprecationWarning.
- We added an extra
repr argument to control the repr. Let's emit a DeprecationWarning if it is passed.
- The default repr is different:
<name> for us, just name for the builtin. Let's just change this.
- We made our Sentinel not picklable; the builtin is picklable by name. So let's add a
__module__ attribute inferred from the caller (can reuse _set_module) and a __reduce__ that just returns self.__name__.
- The builtin doesn't support weakrefs; our version does because it's in Python. I don't know of a way to deprecate our support, so let's just document this difference.
- The builtin exposes a
__name__ attribute; we have _name. Again let's just change this.
- There are some observable changes from the builtin being in C (e.g., the type is immutable), but let's not worry about that.
There are three open PRs about changing Sentinel. #715 and #732 make changes that introduce further incompatibilities, so I'm going to close those. #617 goes in the right direction but also introduces some further incompatible changes.
PEP-661 was accepted, but it is implemented a little differently than our
typing_extensions.Sentinel. Let's see how we can make the typing-extensions version better match the version that will be in Python 3.15, while keeping backward compatibility for users who may already be usingtyping_extensions.Sentinel.Here are the relevant differences:
typing_extensions.Sentinel; 3.15 will havebuiltins.sentinel(lowercase). Let's not worry about the name. On Python 3.15 we'll re-exportbuiltins.sentinelastyping_extensions.Sentinel.builtins.sentinelwill not be. Let's add an__init_subclass__that emits a DeprecationWarning.reprargument to control the repr. Let's emit a DeprecationWarning if it is passed.<name>for us, justnamefor the builtin. Let's just change this.__module__attribute inferred from the caller (can reuse_set_module) and a__reduce__that just returnsself.__name__.__name__attribute; we have_name. Again let's just change this.There are three open PRs about changing Sentinel. #715 and #732 make changes that introduce further incompatibilities, so I'm going to close those. #617 goes in the right direction but also introduces some further incompatible changes.