Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix annotation formatting for builtin types in Python 2.x #1

Merged
merged 1 commit into from May 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion funcsigs/__init__.py
Expand Up @@ -30,7 +30,7 @@

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)
Expand Down
27 changes: 27 additions & 0 deletions 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()