asyncio: Add asyncio.compat module

Move compatibility helpers for the different Python versions to a new
asyncio.compat module.
This commit is contained in:
Victor Stinner 2015-07-25 02:23:21 +02:00
parent f05b79dbd2
commit 71080fc351
8 changed files with 35 additions and 30 deletions

View file

@ -17,12 +17,11 @@ import sys
import threading
import traceback
_PY34 = sys.version_info >= (3, 4)
from asyncio import compat
def _get_function_source(func):
if _PY34:
if compat.PY34:
func = inspect.unwrap(func)
elif hasattr(func, '__wrapped__'):
func = func.__wrapped__
@ -31,7 +30,7 @@ def _get_function_source(func):
return (code.co_filename, code.co_firstlineno)
if isinstance(func, functools.partial):
return _get_function_source(func.func)
if _PY34 and isinstance(func, functools.partialmethod):
if compat.PY34 and isinstance(func, functools.partialmethod):
return _get_function_source(func.func)
return None