
Am 23.09.20 um 18:19 schrieb Anthony Sottile:
I think this would still be useful for replacing functions which return `-> Any` currently (because of the burden of returning a Union on callers - essentially a slightly-safer-but-still-unsafe-Any).
for example, I think it would be useful for a type checker / IDE to produce an error on something like this:
resp = json.load(f) print(resp.definitely_not_a_thing)
but allow any of the attributes / methods of the union of all of the attributes / methods of the `AnyOf` type:
resp = json.load(f) print(resp['this_is_a_thing'])
It's still unsound, but it's a strict improvement over Any
I guess for clarity in definition: - Union[T1, T2] only allows attributes which are the _intersection_ of those provided by T1 & T2 - AnyOf[T1, T2] allows attributes which are the _union_ of those provided by T1 | T2
Thank you for explaining it more eloquently than I could. "Intersection" was probably not the right to use, as Eric Traut pointed out. - Sebastian