mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Remove common.value
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
from jedi.common.value import BaseValueSet, BaseValue
|
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
class BaseValue(object):
|
|
||||||
def __init__(self, inference_state, parent_context=None):
|
|
||||||
self.inference_state = inference_state
|
|
||||||
self.parent_context = parent_context
|
|
||||||
|
|
||||||
def get_root_context(self):
|
|
||||||
value = self
|
|
||||||
while True:
|
|
||||||
if value.parent_context is None:
|
|
||||||
return value
|
|
||||||
value = value.parent_context
|
|
||||||
|
|
||||||
|
|
||||||
class BaseValueSet(object):
|
|
||||||
def __init__(self, iterable):
|
|
||||||
self._set = frozenset(iterable)
|
|
||||||
for value in iterable:
|
|
||||||
assert not isinstance(value, BaseValueSet)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _from_frozen_set(cls, frozenset_):
|
|
||||||
self = cls.__new__(cls)
|
|
||||||
self._set = frozenset_
|
|
||||||
return self
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_sets(cls, sets):
|
|
||||||
"""
|
|
||||||
Used to work with an iterable of set.
|
|
||||||
"""
|
|
||||||
aggregated = set()
|
|
||||||
for set_ in sets:
|
|
||||||
if isinstance(set_, BaseValueSet):
|
|
||||||
aggregated |= set_._set
|
|
||||||
else:
|
|
||||||
aggregated |= frozenset(set_)
|
|
||||||
return cls._from_frozen_set(frozenset(aggregated))
|
|
||||||
|
|
||||||
def __or__(self, other):
|
|
||||||
return self._from_frozen_set(self._set | other._set)
|
|
||||||
|
|
||||||
def __and__(self, other):
|
|
||||||
return self._from_frozen_set(self._set & other._set)
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
for element in self._set:
|
|
||||||
yield element
|
|
||||||
|
|
||||||
def __bool__(self):
|
|
||||||
return bool(self._set)
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self._set)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return 'S{%s}' % (', '.join(str(s) for s in self._set))
|
|
||||||
|
|
||||||
def filter(self, filter_func):
|
|
||||||
return self.__class__(filter(filter_func, self._set))
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
def mapper(*args, **kwargs):
|
|
||||||
return self.from_sets(
|
|
||||||
getattr(value, name)(*args, **kwargs)
|
|
||||||
for value in self._set
|
|
||||||
)
|
|
||||||
return mapper
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self._set == other._set
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not self.__eq__(other)
|
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return hash(self._set)
|
|
||||||
@@ -13,7 +13,6 @@ from parso.python.tree import Name
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi._compatibility import zip_longest, unicode
|
from jedi._compatibility import zip_longest, unicode
|
||||||
from jedi.parser_utils import clean_scope_docstring
|
from jedi.parser_utils import clean_scope_docstring
|
||||||
from jedi.common import BaseValueSet, BaseValue
|
|
||||||
from jedi.inference.helpers import SimpleGetItemNotFound
|
from jedi.inference.helpers import SimpleGetItemNotFound
|
||||||
from jedi.inference.utils import safe_property
|
from jedi.inference.utils import safe_property
|
||||||
from jedi.inference.cache import inference_state_as_method_param_cache
|
from jedi.inference.cache import inference_state_as_method_param_cache
|
||||||
@@ -136,7 +135,7 @@ class HelperValueMixin(object):
|
|||||||
return self._as_context(*args, **kwargs)
|
return self._as_context(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Value(HelperValueMixin, BaseValue):
|
class Value(HelperValueMixin):
|
||||||
"""
|
"""
|
||||||
To be implemented by subclasses.
|
To be implemented by subclasses.
|
||||||
"""
|
"""
|
||||||
@@ -145,6 +144,17 @@ class Value(HelperValueMixin, BaseValue):
|
|||||||
# very important containers.
|
# very important containers.
|
||||||
array_type = None
|
array_type = None
|
||||||
|
|
||||||
|
def __init__(self, inference_state, parent_context=None):
|
||||||
|
self.inference_state = inference_state
|
||||||
|
self.parent_context = parent_context
|
||||||
|
|
||||||
|
def get_root_context(self):
|
||||||
|
value = self
|
||||||
|
while True:
|
||||||
|
if value.parent_context is None:
|
||||||
|
return value
|
||||||
|
value = value.parent_context
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api_type(self):
|
def api_type(self):
|
||||||
# By default just lower name of the class. Can and should be
|
# By default just lower name of the class. Can and should be
|
||||||
@@ -408,7 +418,70 @@ def _getitem(value, index_values, contextualized_node):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class ValueSet(BaseValueSet):
|
class ValueSet(object):
|
||||||
|
def __init__(self, iterable):
|
||||||
|
self._set = frozenset(iterable)
|
||||||
|
for value in iterable:
|
||||||
|
assert not isinstance(value, ValueSet)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_frozen_set(cls, frozenset_):
|
||||||
|
self = cls.__new__(cls)
|
||||||
|
self._set = frozenset_
|
||||||
|
return self
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_sets(cls, sets):
|
||||||
|
"""
|
||||||
|
Used to work with an iterable of set.
|
||||||
|
"""
|
||||||
|
aggregated = set()
|
||||||
|
for set_ in sets:
|
||||||
|
if isinstance(set_, ValueSet):
|
||||||
|
aggregated |= set_._set
|
||||||
|
else:
|
||||||
|
aggregated |= frozenset(set_)
|
||||||
|
return cls._from_frozen_set(frozenset(aggregated))
|
||||||
|
|
||||||
|
def __or__(self, other):
|
||||||
|
return self._from_frozen_set(self._set | other._set)
|
||||||
|
|
||||||
|
def __and__(self, other):
|
||||||
|
return self._from_frozen_set(self._set & other._set)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for element in self._set:
|
||||||
|
yield element
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return bool(self._set)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._set)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return 'S{%s}' % (', '.join(str(s) for s in self._set))
|
||||||
|
|
||||||
|
def filter(self, filter_func):
|
||||||
|
return self.__class__(filter(filter_func, self._set))
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
def mapper(*args, **kwargs):
|
||||||
|
return self.from_sets(
|
||||||
|
getattr(value, name)(*args, **kwargs)
|
||||||
|
for value in self._set
|
||||||
|
)
|
||||||
|
return mapper
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self._set == other._set
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(self._set)
|
||||||
|
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return ValueSet(c.py__class__() for c in self._set)
|
return ValueSet(c.py__class__() for c in self._set)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user