From 77a486e03c370c50518a05eb9376165d51e26a16 Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Sun, 12 Oct 2014 14:46:32 +1100 Subject: [PATCH] The inspect.signature() method was only added in Python 3.3. #31 --- docs/changes.rst | 12 ++++++++++++ src/decorators.py | 6 ++++-- tests/conftest.py | 10 +++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index b852f84..7e484e3 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -1,6 +1,18 @@ Release Notes ============= +Version 1.9.1 +------------- + +**Bugs Fixed** + +* The ``inspect.signature()`` function was only added in Python 3.3. + Use fallback when doesn't exist and on Python 3.2 or earlier Python 3 + versions. + + Note that testing is only performed for Python 3.3+, so it isn't + actually known if the ``wrapt`` package works on Python 3.2. + Version 1.9.0 ------------- diff --git a/src/decorators.py b/src/decorators.py index f3cdb52..d33ca11 100644 --- a/src/decorators.py +++ b/src/decorators.py @@ -13,8 +13,10 @@ from inspect import getargspec, ismethod, isclass from collections import namedtuple from threading import Lock, RLock -if not PY2: +try: from inspect import signature +except ImportError: + pass from .wrappers import (FunctionWrapper, BoundFunctionWrapper, ObjectProxy, CallableObjectProxy) @@ -72,7 +74,7 @@ class _AdapterFunctionSurrogate(CallableObjectProxy): @property def __signature__(self): - if PY2: + if 'signature' not in globals(): return self._self_adapter.__signature__ else: # Can't allow this to fail on Python 3 else it falls diff --git a/tests/conftest.py b/tests/conftest.py index 83b43ce..8dff855 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,13 +1,17 @@ import pytest -from compat import PY2, PY3 +import sys + +version = tuple(sys.version_info[:2]) class DummyCollector(pytest.collect.File): def collect(self): return [] def pytest_pycollect_makemodule(path, parent): - if "py3" in path.basename and not PY3: + if '_py33' in path.basename and version < (3, 3): return DummyCollector(path, parent=parent) - if "py2" in path.basename and not PY2: + if '_py3' in path.basename and version < (3, 0): + return DummyCollector(path, parent=parent) + if '_py2' in path.basename and version >= (3, 0): return DummyCollector(path, parent=parent)