gh-104050: Add basic typing to CConverter in clinic.py by erlend-aasland · Pull Request #104538 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to be done now (and you may not like the suggestion), but you could use an enum for all the sentinels that are defined in clinic.py, instead of defining three separate classes (Unspecified, Null and Unknown):
import enum from typing import Final class Sentinels(enum.Enum): unspecified = 'Unspecified' NULL = 'Null' unknown = 'Unknown' def __repr__(self): return f'<{self.value}>' unspecified: Final = Sentinels.unspecified NULL: Final = Sentinels.NULL unknown: Final = Sentinels.unknown
If you did that, then you'd be able to use a typing.Literal annotation here, which would be more expressive of the fact that unspecified is a singleton:
| annotation: str | Unspecified = unspecified, | |
| annotation: str | Literal[Sentinels.unspecified] = unspecified, |