kuroko/test/testSpecialDecorators.krk
K. Lange 6b3f8de63b Implement general __get__/__set__ descriptors
property objects are no longer a special case and have been simplified
old-style native properties can probably all be removed as well, but, todo
2021-03-10 20:24:12 +09:00

46 lines
859 B
Python

class Foo(object):
myBar = 42
@staticmethod
def foo():
print("No args!")
@property
def bar(*setter):
if setter:
print("Called as a setter:", setter)
self.myBar = setter[0]
return self.myBar
@classmethod
def fromString(cls, string):
print(cls, string)
class Bar(Foo):
Foo.foo()
print(Foo().bar)
let f = Foo()
f.myBar = 48
print(f.bar)
f.bar = 102
print(f.bar)
Foo.fromString("test")
f.fromString("test")
Bar.fromString("test")
class Baz(object):
myBar = 42
@property
def bar(self):
print("I am a Python-style @property!")
return self.myBar
@bar.setter
def bar(self,value):
print("I am a Python-style @property's setter called with", value)
self.myBar = value
let b = Baz()
print(b.bar)
b.bar = 0xDEADBEEF
print(b.bar)