Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
7c6073cf
Commit
7c6073cf
authored
May 28, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make Coroutine ABC inherit from Awaitable
parent
c22c0fb9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
43 deletions
+44
-43
Cython/Utility/Coroutine.c
Cython/Utility/Coroutine.c
+44
-43
No files found.
Cython/Utility/Coroutine.c
View file @
7c6073cf
...
...
@@ -1451,22 +1451,49 @@ Generator.register(_cython_generator_type)
#endif
#ifdef __Pyx_Coroutine_USED
CSTRING
(
"""\
def mk_
coroutin
e():
def mk_
awaitabl
e():
from abc import abstractmethod, ABCMeta
"""
)
#if PY_MAJOR_VERSION >= 3
CSTRING
(
"""\
class
Coroutin
e(metaclass=ABCMeta):
class
Awaitabl
e(metaclass=ABCMeta):
"""
)
#else
CSTRING
(
"""\
class
Coroutin
e(object):
class
Awaitabl
e(object):
__metaclass__ = ABCMeta
"""
)
#endif
CSTRING
(
"""\
__slots__ = ()
@abstractmethod
def __await__(self):
yield
@classmethod
def __subclasshook__(cls, C):
if cls is Awaitable:
for B in C.__mro__:
if '__await__' in B.__dict__:
if B.__dict__['__await__']:
return True
break
return NotImplemented
return Awaitable
try:
Awaitable = _module.Awaitable
except AttributeError:
Awaitable = _module.Awaitable = mk_awaitable()
def mk_coroutine():
from abc import abstractmethod, ABCMeta
class Coroutine(Awaitable):
__slots__ = ()
@abstractmethod
def send(self, value):
'''Send a value into the coroutine.
...
...
@@ -1497,6 +1524,20 @@ def mk_coroutine():
else:
raise RuntimeError('coroutine ignored GeneratorExit')
@classmethod
def __subclasshook__(cls, C):
if cls is Coroutine:
mro = C.__mro__
for method in ('__await__', 'send', 'throw', 'close'):
for base in mro:
if method in base.__dict__:
break
else:
return NotImplemented
return True
return NotImplemented
return Coroutine
try:
...
...
@@ -1504,46 +1545,6 @@ try:
except AttributeError:
Coroutine = _module.Coroutine = mk_coroutine()
Coroutine.register(_cython_coroutine_type)
def mk_awaitable():
from abc import abstractmethod, ABCMeta
"""
)
#if PY_MAJOR_VERSION >= 3
CSTRING
(
"""\
class Awaitable(metaclass=ABCMeta):
"""
)
#else
CSTRING
(
"""\
class Awaitable(object):
__metaclass__ = ABCMeta
"""
)
#endif
CSTRING
(
"""\
__slots__ = ()
@abstractmethod
def __await__(self):
yield
@classmethod
def __subclasshook__(cls, C):
if cls is Awaitable:
for B in C.__mro__:
if '__await__' in B.__dict__:
if B.__dict__['__await__']:
return True
break
return NotImplemented
return Awaitable
try:
Awaitable = _module.Awaitable
except AttributeError:
Awaitable = _module.Awaitable = mk_awaitable()
Awaitable.register(Coroutine)
Awaitable.register(_cython_coroutine_type)
"""
)
#endif
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment