mirror of
https://github.com/davidhalter/jedi.git
synced 2026-08-18 04:47:59 +08:00
python 3 compatibility: new method 'use_metaclass'
This commit is contained in:
@@ -106,3 +106,9 @@ try:
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
except ImportError:
|
except ImportError:
|
||||||
reduce = reduce
|
reduce = reduce
|
||||||
|
|
||||||
|
def use_metaclass(meta, *bases):
|
||||||
|
""" Create a class with a metaclass. """
|
||||||
|
if not bases:
|
||||||
|
bases = (object,)
|
||||||
|
return meta("HackClass", bases, {})
|
||||||
|
|||||||
+1
-1
@@ -135,7 +135,7 @@ def dec(func):
|
|||||||
else:
|
else:
|
||||||
# must be instance
|
# must be instance
|
||||||
stmt = element.var_args.parent_stmt()
|
stmt = element.var_args.parent_stmt()
|
||||||
print ' ' * counter + 'recursion,', stmt
|
print(' ' * counter + 'recursion,', stmt)
|
||||||
counter += 1
|
counter += 1
|
||||||
res = func(*args, **kwargs)
|
res = func(*args, **kwargs)
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|||||||
+2
-4
@@ -19,7 +19,7 @@ TODO nonlocal statement, needed or can be ignored?
|
|||||||
TODO __ instance attributes should not be visible outside of the class.
|
TODO __ instance attributes should not be visible outside of the class.
|
||||||
TODO getattr / __getattr__ / __getattribute__ ?
|
TODO getattr / __getattr__ / __getattribute__ ?
|
||||||
"""
|
"""
|
||||||
from _compatibility import next, property, hasattr, is_py3k
|
from _compatibility import next, property, hasattr, is_py3k, use_metaclass
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import itertools
|
import itertools
|
||||||
@@ -266,13 +266,11 @@ class Instance(Executable):
|
|||||||
(self.__class__.__name__, self.base, len(self.var_args or []))
|
(self.__class__.__name__, self.base, len(self.var_args or []))
|
||||||
|
|
||||||
|
|
||||||
class InstanceElement(object):
|
class InstanceElement(use_metaclass(CachedMetaClass)):
|
||||||
"""
|
"""
|
||||||
InstanceElement is a wrapper for any object, that is used as an instance
|
InstanceElement is a wrapper for any object, that is used as an instance
|
||||||
variable (e.g. self.variable or class methods).
|
variable (e.g. self.variable or class methods).
|
||||||
"""
|
"""
|
||||||
__metaclass__ = CachedMetaClass
|
|
||||||
|
|
||||||
def __init__(self, instance, var):
|
def __init__(self, instance, var):
|
||||||
if isinstance(var, parsing.Function):
|
if isinstance(var, parsing.Function):
|
||||||
var = Function(var)
|
var = Function(var)
|
||||||
|
|||||||
Reference in New Issue
Block a user