It is ugly but probably less ugly than creating special sentinel.
Maybe so; nevertheless, it's an established pattern people are already using (see this article from over 10 years ago). Even if they wanted to change, they may not be able to because of backwards compatibility. They would still benefit from the right tools.
Python doesn't support function overloading, that is the reason we even think about sentinel for arguments.
It supports overloading-like behavior, and that's enough; this is acknowledged by the existence of typing.overload.
Your version with MissingType has other problems: [...]
The exact same problems None has when it's not a valid value. None is different from the variable type, that's why you have Optional[VarType], which is an alias for Union[VarType, None]; you can model this in exactly the same way: Union[VarType, MissingType]; here's an example.
Formal solution would be to use wrapper class (like Java's java.lang.Long for type long) , but it is probably extremally inefficient in critical cases, maybe named tuple is better alternative?
Maybe so, but as I said, sentinel objects are an already established pattern.
Also, from the perspective of a user, wrapping all the objects from an iterable in another type is cumbersome. As an API designer, I'd prefer to do the ugly thing myself once, so many users using my library don't have to.
Rust has enums for variables that are a "union" of types (union as in sets, not as in C). I don't why see Python wouldn't have something similar (it has, with Union).
I understand there is a need for missing value, but local solutions are working. You can unify convention for specific project, but there is no reason to make it a feature
Local solutions are not working for the stdlib devs, as explained in the PEP. This is a feature for them (see Abstract).
People can keep using their own sentinels, for old and new projects alike. If they have the same needs as the stdlib, they can use the ones from stdlib, but they don't have to.
View all comments
Show parent comment
2
u/genericlemon24 Jun 07 '21
Maybe so; nevertheless, it's an established pattern people are already using (see this article from over 10 years ago). Even if they wanted to change, they may not be able to because of backwards compatibility. They would still benefit from the right tools.
It supports overloading-like behavior, and that's enough; this is acknowledged by the existence of typing.overload.
The exact same problems None has when it's not a valid value. None is different from the variable type, that's why you have Optional[VarType], which is an alias for Union[VarType, None]; you can model this in exactly the same way: Union[VarType, MissingType]; here's an example.
Maybe so, but as I said, sentinel objects are an already established pattern.
Also, from the perspective of a user, wrapping all the objects from an iterable in another type is cumbersome. As an API designer, I'd prefer to do the ugly thing myself once, so many users using my library don't have to.
Rust has enums for variables that are a "union" of types (union as in sets, not as in C). I don't why see Python wouldn't have something similar (it has, with Union).
Local solutions are not working for the stdlib devs, as explained in the PEP. This is a feature for them (see Abstract).
People can keep using their own sentinels, for old and new projects alike. If they have the same needs as the stdlib, they can use the ones from stdlib, but they don't have to.