From 561591252bd029981952c5c229f4cf27832d34a1 Mon Sep 17 00:00:00 2001 From: saarni Date: Thu, 5 Feb 2015 12:14:21 +0200 Subject: use getfullargspec in PY3, allowing annotations in subscribers --- CONTRIBUTORS.txt | 2 ++ pyramid/config/util.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e4132cda5..adf2224a5 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -238,3 +238,5 @@ Contributors - Hugo Branquinho, 2014/11/25 - Adrian Teng, 2014/12/17 + +- Ilja Everila, 2015/02/05 diff --git a/pyramid/config/util.py b/pyramid/config/util.py index 892592196..b91f3f7ab 100644 --- a/pyramid/config/util.py +++ b/pyramid/config/util.py @@ -22,6 +22,12 @@ ActionInfo = ActionInfo # support bw compat imports MAX_ORDER = 1 << 30 DEFAULT_PHASH = md5().hexdigest() +# support annotations and keyword-only arguments in PY3 +try: + getargspec = inspect.getfullargspec +except AttributeError: + getargspec = inspect.getargspec + def as_sorted_tuple(val): if not is_nonstr_iter(val): val = (val,) @@ -201,7 +207,7 @@ def takes_one_arg(callee, attr=None, argname=None): return False try: - argspec = inspect.getargspec(fn) + argspec = getargspec(fn) except TypeError: return False -- cgit v1.2.3 From 0ccb82204b8d04f8ffeb8b49a94fb77f981d1122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Everil=C3=A4?= Date: Thu, 5 Feb 2015 19:58:54 +0200 Subject: PY3 only test for function annotations --- pyramid/tests/test_config/test_util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_config/test_util.py b/pyramid/tests/test_config/test_util.py index bb61714ae..c9b0e9e9b 100644 --- a/pyramid/tests/test_config/test_util.py +++ b/pyramid/tests/test_config/test_util.py @@ -1,5 +1,5 @@ import unittest -from pyramid.compat import text_ +from pyramid.compat import text_, PY3 class TestPredicateList(unittest.TestCase): @@ -568,6 +568,14 @@ class Test_takes_one_arg(unittest.TestCase): foo = Foo() self.assertTrue(self._callFUT(foo.method)) + if PY3: + def test_function_annotations(self): + def foo(bar): + """ """ + # avoid SyntaxErrors in python2 + foo.__annotations__.update({'bar': 'baz'}) + self.assertTrue(self._callFUT(foo)) + class TestNotted(unittest.TestCase): def _makeOne(self, predicate): from pyramid.config.util import Notted -- cgit v1.2.3 From d49949081da1669914ddebb487c87edba3f41000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Everil=C3=A4?= Date: Thu, 5 Feb 2015 20:48:54 +0200 Subject: ugly nop dict update hack for PY2 and coverage --- pyramid/tests/test_config/test_util.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyramid/tests/test_config/test_util.py b/pyramid/tests/test_config/test_util.py index c9b0e9e9b..0d0de9579 100644 --- a/pyramid/tests/test_config/test_util.py +++ b/pyramid/tests/test_config/test_util.py @@ -568,13 +568,12 @@ class Test_takes_one_arg(unittest.TestCase): foo = Foo() self.assertTrue(self._callFUT(foo.method)) - if PY3: - def test_function_annotations(self): - def foo(bar): - """ """ - # avoid SyntaxErrors in python2 - foo.__annotations__.update({'bar': 'baz'}) - self.assertTrue(self._callFUT(foo)) + def test_function_annotations(self): + def foo(bar): + """ """ + # avoid SyntaxErrors in python2, this if effectively nop + getattr(foo, '__annotations__', {}).update({'bar': 'baz'}) + self.assertTrue(self._callFUT(foo)) class TestNotted(unittest.TestCase): def _makeOne(self, predicate): -- cgit v1.2.3 From d6ff994619d18981dbde6dce7e8a10140f063e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Everil=C3=A4?= Date: Thu, 5 Feb 2015 21:01:24 +0200 Subject: remove unused import --- pyramid/tests/test_config/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid/tests/test_config/test_util.py b/pyramid/tests/test_config/test_util.py index 0d0de9579..ccf7fa260 100644 --- a/pyramid/tests/test_config/test_util.py +++ b/pyramid/tests/test_config/test_util.py @@ -1,5 +1,5 @@ import unittest -from pyramid.compat import text_, PY3 +from pyramid.compat import text_ class TestPredicateList(unittest.TestCase): -- cgit v1.2.3