On 1/25/21 1:33 PM, Guido van Rossum wrote:
First impressions:
I noticed that none of your examples actually show how you would write the body of a function like isassignable(). Are you assuming that those implementations just introspect the runtime representation?
Yes. Here's a simpler function than trycast: from typing import cast, get_args, get_origin def ununion(form: TypeForm) -> List[TypeForm]: if get_origin(form) is Union: return cast(List[TypeForm], get_args(form)) else: return [form] For trycast, I have an implementation here: https://github.com/davidfstr/trycast/blob/f59cf5ad18402cc3c156de741670ccac6a...
I also saw this:
If you want a typechecker to infer a TypeForm variable type for a bare assignment, use the walrus operator instead of the assignment operator:
``` NULL_TYPE := type(None) # infers NULL_TYPE as having type TypeForm ```
The walrus operator syntactically cannot be used at the top level, so this clever hack won't work.
Ah ha. I'll take out related examples then. -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy