[Python-ideas] "Sum" Type hinting [was: Type hinting for path-related functions]

Stephen J. Turnbull stephen at xemacs.org
Sun May 15 13:22:53 EDT 2016

Koos Zevenhoven writes:

 > I just don't want to say I broke the type hinting for os.path.*

Blame it on Brett. :-)

 > But if I'm told Unions are sufficient,

Unions aren't.  TypeVars are (and they're basically what you proposed
as a solution, I just didn't recognize them in the context of "Union").

 > There is nothing suspicious about that Union there. "Union[str, bytes]
 > -> str" is a perfectly good type hint for os.fsdecode. You can't get
 > any more precise than that.

Unions are suspicious as *values*, not as arguments.  Fortunately,
AnyStr is not a Union.

More information about the Python-ideas mailing list