Eric Traut wrote:
"""It must be possible to express the type guard within the function signature.
In other words, the implementation should not need to be present. This is
important for compatibility with type stubs and to guarantee consistent
behaviors between type checkers."""
Can type stubs include a docstring? If so, then adding subsequent lines that
are only parameter annotations doesn't seem like a problem.
And frankly, allowing subsequent lines (possibly restricted to
first-except-docstrings) doesn't seem any more invasive than adding another
magic type that has to be interpreted differently. (I understand it might be
more coding in practice, based on one solution having already been written.)
def is_str_list(val: List[object]) -> bool:
"""Determines whether all objects in the list are strings"""
val: NarrowsTo[List[str]]
I agree that Greg's suggestion of
def is_str_list(val: Constrains[List[object]:List[str]) -> bool:
also meets the criteria you list, but ... as a human reader, that signature is
getting too heavy.
I'll also note that I don't think TypeScript is a good model for "this won't be
a problem." It is probably a good model for "this will work for the people who
*want* to go whole hog on explicit typing", but for people who are at best
agnostic about typing ... they would stick with JavaScript, instead of using
TypeScript. Alas, this change isn't being proposed just for TypedPython; it is
being proposed for baseline python.
-jJ
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/DXVRLPGFUYQ2CDNMQSS66M7RITSGIB3R/
Code of Conduct: http://python.org/psf/codeofconduct/