Hi folks! I'm sending this email because I'd love to work on introduction support for Intersection to python's typing capabilities. I'd love to know if someone is already working on this and if not, I'd like to try and work on it, but I'd need some support if possible ^^ I've sketched out a basic plan[0], basically the initial idea is to write an initial PEP based on the discussion[1] around typing.Intersection, make a prototype implementation and then try to get feedback on the PEP and implementation. Does that make sense? Would someone be able to help me with this? And, again, if someone is already working on this, let me know, I'm ok with that too :D [0] My rough plan and basic notes: https://hackmd.io/0ymmrUtGTG-CEiw32qVfiQ [1] Issues regarding typing.Intersection: https://github.com/python/typing/issues/213
Hi Patrick, I think you are on the right track. I don't think that anyone is working on this. 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! 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). - The example with two typeddicts could be satisfied by creating a third typed dict that has both fields. This works: from typing import * class A(TypedDict): x: int class B(TypedDict): y: str class AB(TypedDict): x: int y: str def f(a: A): ... def g(b: B): ... ab: AB = {'x': 1, 'y': ''} f(ab) g(ab) On Tue, Nov 16, 2021 at 3:48 PM Patrick Arminio <patrick.arminio@gmail.com> wrote:
Hi folks!
I'm sending this email because I'd love to work on introduction support for Intersection to python's typing capabilities. I'd love to know if someone is already working on this and if not, I'd like to try and work on it, but I'd need some support if possible ^^
I've sketched out a basic plan[0], basically the initial idea is to write an initial PEP based on the discussion[1] around typing.Intersection, make a prototype implementation and then try to get feedback on the PEP and implementation.
Does that make sense? Would someone be able to help me with this? And, again, if someone is already working on this, let me know, I'm ok with that too :D
[0] My rough plan and basic notes: https://hackmd.io/0ymmrUtGTG-CEiw32qVfiQ [1] Issues regarding typing.Intersection: https://github.com/python/typing/issues/213 _______________________________________________ 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-change-the-world/>
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
Hey Patrick, I'm interested in collaborating on a PEP for intersections. My gut feeling is that specifying it will not be too hard, because intersection types are dual to unions and unions are already mostly specified in PEP-483, PEP-484, PEP-604 and PEP-544 (for union of protocols). Should we set up a Zoom/Meet call to discuss the next steps? Cheers, Sergei On Tue, Nov 16, 2021 at 11:48 PM Patrick Arminio <patrick.arminio@gmail.com> wrote:
Hi folks!
I'm sending this email because I'd love to work on introduction support for Intersection to python's typing capabilities. I'd love to know if someone is already working on this and if not, I'd like to try and work on it, but I'd need some support if possible ^^
I've sketched out a basic plan[0], basically the initial idea is to write an initial PEP based on the discussion[1] around typing.Intersection, make a prototype implementation and then try to get feedback on the PEP and implementation.
Does that make sense? Would someone be able to help me with this? And, again, if someone is already working on this, let me know, I'm ok with that too :D
[0] My rough plan and basic notes: https://hackmd.io/0ymmrUtGTG-CEiw32qVfiQ [1] Issues regarding typing.Intersection: https://github.com/python/typing/issues/213 _______________________________________________ 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: sergei.a.lebedev@gmail.com
On Wed, 17 Nov 2021 at 10:44, Sergei Lebedev <sergei.a.lebedev@gmail.com> wrote:
Hey Patrick,
I'm interested in collaborating on a PEP for intersections. My gut feeling is that specifying it will not be too hard, because intersection types are dual to unions and unions are already mostly specified in PEP-483, PEP-484, PEP-604 and PEP-544 (for union of protocols).
I'm unsure about that, union types seem much simpler than intersections, but maybe I'm missing something!
Should we set up a Zoom/Meet call to discuss the next steps?
Sure! https://koalendar.com/e/meet-with-patrick-arminio
Cheers, Sergei
On Tue, Nov 16, 2021 at 11:48 PM Patrick Arminio < patrick.arminio@gmail.com> wrote:
Hi folks!
I'm sending this email because I'd love to work on introduction support for Intersection to python's typing capabilities. I'd love to know if someone is already working on this and if not, I'd like to try and work on it, but I'd need some support if possible ^^
I've sketched out a basic plan[0], basically the initial idea is to write an initial PEP based on the discussion[1] around typing.Intersection, make a prototype implementation and then try to get feedback on the PEP and implementation.
Does that make sense? Would someone be able to help me with this? And, again, if someone is already working on this, let me know, I'm ok with that too :D
[0] My rough plan and basic notes: https://hackmd.io/0ymmrUtGTG-CEiw32qVfiQ [1] Issues regarding typing.Intersection: https://github.com/python/typing/issues/213 _______________________________________________ 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: sergei.a.lebedev@gmail.com
-- Patrick Arminio
Hey, I really like where this is going but I'd also like to ask if this could include a Not type as I think both go hand in hand, if you don't think that would be appropriate I'd be happy to work on a PEP for it myself.
My recommendation is not to conflate "Intersection" with "Not". They're very different concepts and they each deserve their own discussions. -- Eric Traut Contributor to Pyright & Pylance Microsoft
participants (5)
-
Eric Traut
-
Guido van Rossum
-
James H-B
-
Patrick Arminio
-
Sergei Lebedev