Even if a variable has a Final qualifier, it’s still a variable. The expression _Nothing.NOTHING is not a valid type expression, and NOTHING is not a valid type alias.
Here is how I recommend handling this pattern such that it is compatible with the type system.
import enum
from typing import Final, Literal
class _Nothing(enum.Enum):
NOTHING = enum.auto()
type NothingType = Literal[_Nothing.NOTHING]
NOTHING: Final = _Nothing.NOTHING
def f(a: str | NothingType = NOTHING): ...
You might also be interested in this thread, which discusses the idea of adding a sentinel facility to the language.