Hm, I hadn’t thought of it that way, but you're right. But that would mean that using an Intersection type is usually a lie, right? (I.e. unsound, I believe is the term?)

On Wed, Sep 23, 2020 at 08:07 Jelle Zijlstra <jelle.zijlstra@gmail.com> wrote:


El mié., 23 sept. 2020 a las 16:48, Guido van Rossum (<guido@python.org>) escribió:
So for a checker that interprets AnyOf fully, there would be no difference with Union, right? It’s just a spelling of Union with a default behavior of Any.

My understanding is that a type checker should accept an operation on a value of type `AnyOf[A, B]` if it is valid on either A or B, but an operation on a value of type `Union[A, B]` is acceptable only if it is valid on both A and B. So `len(x)` where `x: AnyOf[str, int]` would be valid.

That does sound similar to `Intersection`, now that I think of it.
 
Because clearly it can’t be meant to mean Intersection, right?

Still, the example of float**float concerns me. It returns AnyOf[float, complex] but the default should be float. Your proposed notation doesn’t have a way to specify that. (Another fallback could be the join of all the types, but that would be complex, which is undesirable for float**float for pragmatic reasons.)

—Guido

On Wed, Sep 23, 2020 at 02:13 Sebastian Rittau <srittau@rittau.biz> wrote:
Am 22.09.20 um 18:39 schrieb dimvar--- via Typing-sig:

> Re: the use of AnyOf for typing.

> I agree with the folks saying that it's probably not a good idea to introduce an unsafe union. In the cases where more type safety than just using Any is desired, one can use an ordinary union, and the callers of the function can cast the result to their desired type.



Unfortunately that is not true as the many examples in the originally

mentioned ticket prove. Experience has shown that safe unions are

inconvenient as return types in many cases, especially when typing

previously untyped code. Unsafe unions provide a substantial type safety

benefit over the only alternative of using Any.



  - Sebastian



_______________________________________________

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 (mobile)


_______________________________________________


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: jelle.zijlstra@gmail.com




--
--Guido (mobile)