diff options
author | cpopa <devnull@localhost> | 2013-08-14 14:15:31 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2013-08-14 14:15:31 +0300 |
commit | 1c72d69631067e3aff537e2779b3ece6f7cdf1c8 (patch) | |
tree | cda510f21e94b9dc660fbb106d495f7b00628708 | |
parent | 0a20ae3bb8a44cb8f089feae4b0454ec6d0d4b89 (diff) | |
download | astroid-1c72d69631067e3aff537e2779b3ece6f7cdf1c8.tar.gz |
Proper handling of metaclass for class.as_string.
-rw-r--r-- | as_string.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/as_string.py b/as_string.py index fcff19e..b7e6257 100644 --- a/as_string.py +++ b/as_string.py @@ -144,7 +144,17 @@ class AsStringVisitor(object): """return an astroid.Class node as string""" decorate = node.decorators and node.decorators.accept(self) or '' bases = ', '.join([n.accept(self) for n in node.bases]) - bases = bases and '(%s)' % bases or '' + if sys.version_info[0] == 2: + bases = bases and '(%s)' % bases or '' + else: + metaclass = node.metaclass() + if metaclass: + if bases: + bases = '(%s, metaclass=%s)' % (bases, metaclass.name) + else: + bases = '(metaclass=%s)' % metaclass.name + else: + bases = bases and '(%s)' % bases or '' docs = node.doc and '\n%s"""%s"""' % (INDENT, node.doc) or '' return '\n\n%sclass %s%s:%s\n%s\n' % (decorate, node.name, bases, docs, self._stmt_list( node.body)) |