[Python-Dev] Re: Migrate typing in builtin

2019-10-09 Thread Guido van Rossum
Can someone else with a reasonable understanding of the type machinery in CPython help Philippe? IMO the entire _GenericAlias class that's currently implemented in Python in typing.py needs to be reimplemented in C. However for a prototype (to show how other aspects of the proposal will look) it i

[Python-Dev] Re: Migrate typing in builtin

2019-10-09 Thread Philippe Prados
In my current implementation (proof of concept), I must use a trick to detect the _GenericAlias, without import. I check the tp_name. static PyObject* union_to_tuple(PyObject* cls) { //printf("union_to_tuple"); if (!strcmp(Py_TYPE(cls)->tp_name,"_GenericAlias")) { PyObject* origin

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Eric V. Smith
Ivan (who you cc'd) is a good start! Eric On 10/8/2019 8:35 AM, Philippe Prados wrote: Glups. I am not an expert of Pyhton source code. May be after this patch ;-) I think I should discuss with the authors of the module typing, to identify the best strategy. Who is he ? Philippe Le mar.

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Guido van Rossum
That would mean that all of typing will be imported as part of startup, and that module is too heavy for that. Also it might end up on recursion. On Tue, Oct 8, 2019 at 09:06 Brandt Bucher wrote: > I’m a bit confused. For my own understanding: what’s stopping > PyObject_IsInstance/PyObject_IsSub

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Brandt Bucher
I’m a bit confused. For my own understanding: what’s stopping PyObject_IsInstance/PyObject_IsSubclass from just trying PyImport_GetModule("typing") here? If NULL, carry on. Otherwise, check the Union case. Brandt > On Oct 8, 2019, at 05:44, Philippe Prados wrote: > >  > Glups. > > I am not

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Philippe Prados
Glups. I am not an expert of Pyhton source code. May be after this patch ;-) I think I should discuss with the authors of the module typing, to identify the best strategy. Who is he ? Philippe Le mar. 8 oct. 2019 à 10:19, Ivan Levkivskyi a écrit : > You will need to rewrite most of things in

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Ivan Levkivskyi
You will need to rewrite most of things in C. -- Ivan On Tue 8 Oct 2019, 08:53 Philippe Prados, wrote: > Ok, > > But _GenericAlias and dependencies are written with Python > (Lib/typing.py), not with C. > So, I must rewrite the _GenericAlias in C or it's possible to merge the C > and Python in

[Python-Dev] Re: Migrate typing in builtin

2019-10-08 Thread Philippe Prados
Ok, But _GenericAlias and dependencies are written with Python (Lib/typing.py), not with C. So, I must rewrite the _GenericAlias in C or it's possible to merge the C and Python in builtin and add a direct reference to _GenericAlias with C, and add the reference in builtin module ? Philippe Le l

[Python-Dev] Re: Migrate typing in builtin

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 12:02, Philippe Prados wrote: > Because this PEP propose to accept, for all classes > assert isinstance("", int | str) > assert issubclass(int, int | str) > and add an operator __or__() for type type. > def f(list: List[int | str], param: int | None) -> float | str: > pa

[Python-Dev] Re: Migrate typing in builtin

2019-10-07 Thread Ivan Levkivskyi
On Mon, 7 Oct 2019 at 17:16, Guido van Rossum wrote: > Hi Philippe, > > Maybe the implementation of `_GenericAlias` should live in > Objects/typobject.c, and be a part of the public API. Then the "|" overload > on PyType_Type (also there) can reference it directly, it can be exported > from Pytho

[Python-Dev] Re: Migrate typing in builtin

2019-10-07 Thread Guido van Rossum
Hi Philippe, Maybe the implementation of `_GenericAlias` should live in Objects/typobject.c, and be a part of the public API. Then the "|" overload on PyType_Type (also there) can reference it directly, it can be exported from Python/bltinsmodule.c, and typing can reference it as a builtin. --Gui

[Python-Dev] Re: Migrate typing in builtin

2019-10-07 Thread Philippe Prados
Because this PEP propose to accept, for all classes assert isinstance("", int | str) assert issubclass(int, int | str) and add an operator __or__() for type type. def f(list: List[int | str], param: int | None) -> float | str: pass Regards Philippe Le lun. 7 oct. 2019 à 17:29, Random832

[Python-Dev] Re: Migrate typing in builtin

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 10:32, Philippe Prados wrote: > Hello, > > I try to implement a *proof of concept* of Pep-0604 > . > > To do this, the _GenericAlias must be in builtin, because I would like > to update issubclass() and isinstance() to accept Un