diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-09-27 18:41:23 +0200 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-09-27 18:41:23 +0200 |
commit | d110bcf2de4b8bc48e41638cf430f17c5714ffbc (patch) | |
tree | 52402738682049b593a4eee871b16ebadc01bc3d | |
parent | 9609f63ee0c5cd1f52283fea5d1ae8c184f849b0 (diff) | |
download | astroid-git-d110bcf2de4b8bc48e41638cf430f17c5714ffbc.tar.gz |
closes #77188: support lgc.decorators.classproperty
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | rebuilder.py | 10 | ||||
-rw-r--r-- | test/unittest_builder.py | 15 |
3 files changed, 24 insertions, 3 deletions
@@ -11,6 +11,8 @@ Change log for the astng package * #74748: getitem protocal return constant value instead of a Const node (patch by google) + * #77188: support lgc.decorators.classproperty + 2011-07-18 -- 0.22.0 * added column offset information on nodes (patch by fawce) diff --git a/rebuilder.py b/rebuilder.py index ad214758..bac7a095 100644 --- a/rebuilder.py +++ b/rebuilder.py @@ -211,6 +211,8 @@ class TreeRebuilder(object): if isinstance(meth, new.Function): if func_name in ('classmethod', 'staticmethod'): meth.type = func_name + elif func_name == 'classproperty': # see lgc.decorators + meth.type = 'classmethod' meth.extra_decorators.append(newnode.value) except (AttributeError, KeyError): continue @@ -486,9 +488,11 @@ class TreeRebuilder(object): newnode.type = 'method' if newnode.decorators is not None: for decorator_expr in newnode.decorators.nodes: - if isinstance(decorator_expr, new.Name) and \ - decorator_expr.name in ('classmethod', 'staticmethod'): - newnode.type = decorator_expr.name + if isinstance(decorator_expr, new.Name): + if decorator_expr.name in ('classmethod', 'staticmethod'): + newnode.type = decorator_expr.name + elif decorator_expr.name == 'classproperty': + newnode.type = 'classmethod' frame.set_local(newnode.name, newnode) return newnode diff --git a/test/unittest_builder.py b/test/unittest_builder.py index 037243b6..6bbc9886 100644 --- a/test/unittest_builder.py +++ b/test/unittest_builder.py @@ -580,6 +580,7 @@ class FileBuildTC(TestCase): self.assertEqual(len(_locals), 3) self.assertEqual(keys, ['autre', 'local', 'self']) + class ModuleBuildTC(FileBuildTC): def setUp(self): @@ -662,6 +663,20 @@ def func(): self.assertEqual(chain.value, 'None') + def test_lgc_classproperty(self): + '''test expected values of constants after rebuilding''' + code = ''' +from logilab.common.decorators import classproperty + +class A(object): + @classproperty + def hop(cls): + return None +''' + astng = self.builder.string_build(code) + self.assertEqual(astng['A']['hop'].type, 'classmethod') + + if sys.version_info < (3, 0): guess_encoding = builder._guess_encoding |