On Wed, 17 Nov 2021 at 00:29, Guido van Rossum <guido@python.org> wrote:
Hi Patrick,

I think you are on the right track. I don't think that anyone is working on this.
Great 😊 
 
You probably need to find a collaborator who is well versed in one of the type checker implementations -- adding a new construct like this is not a simple task!
I can imagine! I think I'll try to get myself familiar with Pyright and then I'll start asking for help :)
 
Regarding your questions:

- int&str probably can't be satisfied because it would require multiple inheritance from two different C types (the instance layouts are incompatible). But if you had two unrelated classes C1 and C2 defined with class statements in Python, multiple inheritance could produce a type that satisfies C1&C2. Mypy doesn't generally take constraints due to object layout into account, since in the type stubs int and str are also defined using class statements. So it will probably have to accept int&str, but no type you can construct will satisfy it -- it acts as an effective bottom type (has no instances).
Yes, I think we can also take inspiration from Typescript, which allows us to do `Number & String`, but no type will ever satisfy that constraint. My only
fear is that we allow to write intersection types that will never be satisfied and thus confusing users.
 

- The example with two typeddicts could be satisfied by creating a third typed dict that has both fields. This works:
Yes :) So typing.Intersection should work for both classes and typed dictsÂ