1
0
forked from VimPlug/jedi

property / staticmethod / classmethod builtin implementation

This commit is contained in:
David Halter
2012-06-24 00:54:40 +02:00
parent d1f464f0f7
commit e42a534e38
3 changed files with 48 additions and 4 deletions

View File

@@ -14,8 +14,8 @@ TODO annotations ? how ? type evaluation and return?
TODO nonlocal statement TODO nonlocal statement
TODO getattr / __getattr__ / __getattribute__ ? TODO getattr / __getattr__ / __getattribute__ ?
TODO descriptors TODO descriptors (also for classes, for instances it should work)
TODO @staticmethod @classmethod TODO @staticmethod @classmethod (implement descriptors, builtins are done)
TODO variable assignments in classes (see test/completion/classes @230) TODO variable assignments in classes (see test/completion/classes @230)
""" """
from _compatibility import next, property from _compatibility import next, property

View File

@@ -5,3 +5,47 @@ def next(iterator, default=None):
else: else:
return iterator.__next__() return iterator.__next__()
return default return default
class property():
def __init__(self, fget, fset = None, fdel = None, doc = None):
self.fget = fget
self.fset = fset
self.fdel = fdel
self.__doc__ = doc
def __get__(self, obj, cls):
return self.fget(obj)
def __set__(self, obj, value):
self.fset(obj, value)
def __delete__(self, obj):
self.fdel(obj)
def setter(self, func):
self.fset = func
return self
def getter(self, func):
self.fget = func
return self
def deleter(self, func):
self.fdel = func
return self
class staticmethod():
def __init__(self, func):
self.func = func
def __get__(self, obj, cls):
return self.func
class classmethod():
def __init__(self, func):
self.func = func
def __get__(self, obj, cls):
def method(*args, **kwargs):
self.func(cls, *args, **kwargs)
return method

View File

@@ -189,13 +189,13 @@ class B():
return '' return ''
p = Property(t) p = Property(t)
##? str()
B().p
#? [] #? []
B().r() B().r()
#? int() #? int()
B().r B().r
##? str()
B().p
##? [] ##? []
B().p() B().p()