FWIW I've fixed the nits in the repo.
On Fri, Jan 1, 2021 at 7:19 AM David Foster
On 12/27/20 10:02 AM, Eric Traut wrote:
I've updated the [draft PEP](https://github.com/erictraut/peps/blob/master/pep-0647.rst) to incorporate the feedback.
Looks good. A few comments below:
§ "Narrowing of Arbitrary Parameters":
TypeScript's formulation of user-defined type guards allows for any input parameter to be used as the value tested for narrowing. The TypeScript language authors could not recall any real-world examples in TypeScript where the parameter being tested was not the first parameter. For this reason, it was decided unnecessary to burden the Python implementation of user-defined type guards with additional complexity to support a contrived use case. If such use cases are identified in the future, there are ways the TypeGuard mechanism could be extended. This could involve the use of keyword indexing, as proposed in PEP 637.
To make "This could involve the use of keyword indexing" more concrete, suggest actually putting in an example, such as:
``` def is_str_list(failure_message: str, val: List[object]) -> TypeGuard[val=List[str]]: non_strs = [x for x in val if not isinstance(x, str)] if len(non_strs) != 0: print(failure_message % non_strs) return len(non_strs) == 0
parsed_list = ... assert is_str_list('Non-strings: %s', parsed_list) ```
Admittedly this particular is contrived, but is still illustrative.
Discussions-To: Python-Dev
Nit: "Python-Dev" -> "Typing-Sig"
§ "Conditionally Applying TypeGuard Type"
It was suggested that the expression passed as the first argument to a type guard function should retain 👉its👈 existing type if the type of the expression was
Nit: See typo above: 👉its👈
Best, -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: guido@python.org
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...