summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTripp Lilley <tripplilley@gmail.com>2013-01-18 11:30:42 -0500
committerTripp Lilley <tripplilley@gmail.com>2013-01-18 11:30:42 -0500
commita08e4437a27eefdeb77c00aa09f1f5bf8ac68984 (patch)
tree94d31e1a52c69c281ee46b7eb8ebb5fdc8b54862
parent130414e246c8236e20c70f7c4558b6d7ce9d6eb2 (diff)
downloadfuncsigs-a08e4437a27eefdeb77c00aa09f1f5bf8ac68984.tar.gz
fix annotation formatting for builtin types in Python 2.x
-rw-r--r--funcsigs/__init__.py2
-rw-r--r--tests/test_formatannotation.py27
2 files changed, 28 insertions, 1 deletions
diff --git a/funcsigs/__init__.py b/funcsigs/__init__.py
index f2924c3..b9ba326 100644
--- a/funcsigs/__init__.py
+++ b/funcsigs/__init__.py
@@ -30,7 +30,7 @@ _NonUserDefinedCallables = (_WrapperDescriptor,
def formatannotation(annotation, base_module=None):
if isinstance(annotation, type):
- if annotation.__module__ in ('builtins', base_module):
+ if annotation.__module__ in ('builtins', '__builtin__', base_module):
return annotation.__name__
return annotation.__module__+'.'+annotation.__name__
return repr(annotation)
diff --git a/tests/test_formatannotation.py b/tests/test_formatannotation.py
new file mode 100644
index 0000000..fd7a887
--- /dev/null
+++ b/tests/test_formatannotation.py
@@ -0,0 +1,27 @@
+try:
+ # python 2.x
+ import unittest2 as unittest
+except ImportError:
+ # python 3.x
+ import unittest
+
+import funcsigs
+
+
+class TestFormatAnnotation(unittest.TestCase):
+ def test_string (self):
+ self.assertEqual(funcsigs.formatannotation("annotation"),
+ "'annotation'")
+
+ def test_builtin_type (self):
+ self.assertEqual(funcsigs.formatannotation(int),
+ "int")
+
+ def test_user_type (self):
+ class dummy (object): pass
+ self.assertEqual(funcsigs.formatannotation(dummy),
+ "tests.test_formatannotation.dummy")
+
+
+if __name__ == "__main__":
+ unittest.begin()