mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 02:27:06 +08:00
added functool mixins
This commit is contained in:
@@ -177,7 +177,7 @@ class Parser(CachedModule):
|
||||
return {}
|
||||
else:
|
||||
mixin_dct = process_code(f.read())
|
||||
if is_py3k():
|
||||
if is_py3k() and self.name == _Builtin.name:
|
||||
# in the case of Py3k xrange is now range
|
||||
mixin_dct['range'] = mixin_dct['xrange']
|
||||
return mixin_dct
|
||||
|
||||
9
mixin/_functools.py
Normal file
9
mixin/_functools.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class partial():
|
||||
def __init__(self, func, *args, **keywords):
|
||||
self.__func = func
|
||||
self.__args = args
|
||||
self.__keywords = keywords
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
# I know this doesn't work in Python, but Jedi can this ;-)
|
||||
return self.__func(*self.__args, *args, **self.keywords, **kwargs)
|
||||
@@ -31,3 +31,34 @@ weakref.proxy(1)
|
||||
weakref.ref(1)
|
||||
#? int()
|
||||
weakref.ref(1)()
|
||||
|
||||
# -----------------
|
||||
# functools
|
||||
# -----------------
|
||||
import functools
|
||||
|
||||
basetwo = functools.partial(int, base=2)
|
||||
#? int()
|
||||
basetwo()
|
||||
|
||||
def a(a, b):
|
||||
return a, b
|
||||
a = functools.partial(a, 0)
|
||||
|
||||
#? int()
|
||||
a('')[0]
|
||||
#? str()
|
||||
a('')[1]
|
||||
|
||||
def my_decorator(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwds):
|
||||
return f(*args, **kwds)
|
||||
return wrapper
|
||||
|
||||
@my_decorator
|
||||
def example(a):
|
||||
return a
|
||||
|
||||
#? str()
|
||||
example('')
|
||||
|
||||
Reference in New Issue
Block a user