frequenz-floss / frequenz-core-python

Core utilities to complement Python's standard library
https://frequenz-floss.github.io/frequenz-core-python/
MIT License
0 stars 2 forks source link

Add a PEP661-compatible `sentinels` module #37

Closed llucax closed 1 week ago

llucax commented 2 weeks ago

Introduce a new module for creating unique sentinel objects according to PEP661.

This is based in the reference implementation in https://github.com/taleinat/python-stdlib-sentinels (commit 410273e40bdbd1b58a63cebefdf8abcce6c620e3), and adapted to match this repository documentation standards and linting tools.

llucax commented 2 weeks ago

Skipping release notes check as there is no release yet, we'll write the notes when the first release is out.

llucax commented 1 week ago

I tried several alternatives and couldn't make it work with a reasonable syntax, so I guess we need to wait for the official support.

I tried other more old school implementations and they all suck, I guess the best approach for now is still to just do class Sentinel: pass; SENTINEL = Sentinel(), at least until this gets implemented, then at least we can use Literal with SENTINEL: Final = object() and accept Literal[SENTINEL] as argument, which seems still reasonable:

I think I will close for now.