Commit 06a30603 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Decorators: Added capability to refer to attributes as well (like in Python).

parent 0817b5c8
......@@ -2125,9 +2125,13 @@ def p_decorators(s):
while s.sy == 'DECORATOR':
pos = s.position()
s.next()
decorator = ExprNodes.NameNode(
pos, name = Utils.EncodedString(
p_dotted_name(s, as_allowed=0)[2] ))
decstring = p_dotted_name(s, as_allowed=0)[2]
names = decstring.split('.')
decorator = ExprNodes.NameNode(pos, name=Utils.EncodedString(names[0]))
for name in names[1:]:
decorator = ExprNodes.AttributeNode(pos,
attribute=Utils.EncodedString(name),
obj=decorator)
if s.sy == '(':
decorator = p_call(s, decorator)
decorators.append(Nodes.DecoratorNode(pos, decorator=decorator))
......
_ERRORS = u"""
4:4 Expected a newline after decorator
"""
class A:
pass
@A().a
def f():
pass
......@@ -13,6 +13,10 @@ __doc__ = u"""
6
>>> h.HERE
1
>>> i(4)
3
>>> i.HERE
1
"""
class wrap:
......@@ -47,3 +51,13 @@ def g(a,b):
@decorate2(1,2)
def h(a,b):
return a+b+3
class A:
def decorate(self, func):
return decorate(func)
a = A()
@a.decorate
def i(x):
return x - 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment