[Python-Dev] Migrate typing in builtin

2019-10-07 Thread Philippe Prados
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 Union.
These methods are in builtin, and must be run without others modules.

But, the class _GenericAlias is in typing module, with the Python
implementation in Lib/typing.py, and the C implementation is in
Modules/_ctypes.

For you, what is the best approach to move the _GenericAlias and all
dependencies in the builtin "module" ?

Philippe
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/FVDIL2DG3EP7CO452MUZYPATN4R2CEHN/
Code of Conduct: http://python.org/psf/codeofconduct/


[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 Union.
> These methods are in builtin, and must be run without others modules.

Why can't this be handled as an __instancecheck__/__subclasscheck__?
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/UZRHLKTGR7USOD365N57Y2QVUWWMGPJ7/
Code of Conduct: http://python.org/psf/codeofconduct/


[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  a écrit :

> 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 Union.
> > These methods are in builtin, and must be run without others modules.
>
> Why can't this be handled as an __instancecheck__/__subclasscheck__?
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/UZRHLKTGR7USOD365N57Y2QVUWWMGPJ7/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/LASLJP2MRQWSWUHD4PCJJ2D3SOWL6SAD/
Code of Conduct: http://python.org/psf/codeofconduct/


[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.

--Guido

On Mon, Oct 7, 2019 at 8:14 AM 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 Union.
> These methods are in builtin, and must be run without others modules.
>
> But, the class _GenericAlias is in typing module, with the Python
> implementation in Lib/typing.py, and the C implementation is in
> Modules/_ctypes.
>
> For you, what is the best approach to move the _GenericAlias and all
> dependencies in the builtin "module" ?
>
> Philippe
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/FVDIL2DG3EP7CO452MUZYPATN4R2CEHN/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/UPLGMF26ITYIVH4DMQ7YOC5Y7TJGQSXU/
Code of Conduct: http://python.org/psf/codeofconduct/


[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 Python/bltinsmodule.c, and typing can reference it as a builtin.
>

That file (typeobject) is already quite big, so I think we might consider
also creating a new file Objects/genericalias.c, but it is just a minor
wish. I think both ways are fine.

--
Ivan
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/6N2KUJOQRTXTDTDXJL57GECGA5YETA7P/
Code of Conduct: http://python.org/psf/codeofconduct/


[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:
> pass

Oh, sorry, I didn't realize that this also included the | operator, I thought 
this was just for isinstance("", Union[int, str]).
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/52EL5VM6P3CZ7TMN7HOKUS7BCUE6HMFB/
Code of Conduct: http://python.org/psf/codeofconduct/