[Python-Dev] PEP 484 (Type Hints) -- the next draft is here (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Sat Apr 18 19:39:51 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 484 (Type Hints) -- the next draft is here
- Next message (by thread): [Python-Dev] PEP 484 (Type Hints) -- the next draft is here
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum schrieb am 18.04.2015 um 18:38:
That's a good question. We could make it so that you can subclass Generator and instantiate the instances; or we could even make it do some structural type checking. (Please file a pull request or issue for this at github.com/ambv/typehinting .)
Done:
https://github.com/ambv/typehinting/issues/89
But perhaps we should also change asyncio? What check are you talking about?
https://hg.python.org/cpython/file/439517000aa2/Lib/asyncio/coroutines.py#l169
The current (3.5alpha) check in iscoroutine() is an instance check against _COROUTINE_TYPES, which contains types.GeneratorType and another wrapper type. It excludes objects that implement the coroutine protocol without being Python generators, e.g. Cython compiled generators, which mimic the Python generator interface without having byte code in them (meaning, they are not C-level compatible with Python generators). I'm sure the same applies to other compilers like Numba or Nuitka. Supporting asyncio in recent Python releases thus means monkey patching _COROUTINE_TYPES and adding another type to it. Given that it's not a public interface, this seems a bit fragile.
It also seems that this code only appeared somewhere in the 3.4.x release series. Older versions were even worse and did a straight call to inspect.isgenerator() in their iscoroutine() function, which means that the whole function needed to be replaced and wrapped (and even that didn't fix all places where inspect was used).
I guess I should open a (CPython) ticket for this topic, too...
Stefan
- Previous message (by thread): [Python-Dev] PEP 484 (Type Hints) -- the next draft is here
- Next message (by thread): [Python-Dev] PEP 484 (Type Hints) -- the next draft is here
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]