forked from VimPlug/jedi
Start using our own monkeypatch function for some things
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
|
||||||
def traverse_parents(path, include_current=False):
|
def traverse_parents(path, include_current=False):
|
||||||
@@ -10,3 +11,16 @@ def traverse_parents(path, include_current=False):
|
|||||||
yield path
|
yield path
|
||||||
previous = path
|
previous = path
|
||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def monkeypatch(obj, attribute_name, new_value):
|
||||||
|
"""
|
||||||
|
Like pytest's monkeypatch, but as a context manager.
|
||||||
|
"""
|
||||||
|
old_value = getattr(obj, attribute_name)
|
||||||
|
try:
|
||||||
|
setattr(obj, attribute_name, new_value)
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
setattr(obj, attribute_name, old_value)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
||||||
|
from jedi.common.utils import monkeypatch
|
||||||
|
|
||||||
class AbstractLazyContext(object):
|
class AbstractLazyContext(object):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
@@ -40,12 +41,8 @@ class LazyTreeContext(AbstractLazyContext):
|
|||||||
self._predefined_names = dict(context.predefined_names)
|
self._predefined_names = dict(context.predefined_names)
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
old, self._context.predefined_names = \
|
with monkeypatch(self._context, 'predefined_names', self._predefined_names):
|
||||||
self._context.predefined_names, self._predefined_names
|
|
||||||
try:
|
|
||||||
return self._context.eval_node(self.data)
|
return self._context.eval_node(self.data)
|
||||||
finally:
|
|
||||||
self._context.predefined_names = old
|
|
||||||
|
|
||||||
|
|
||||||
def get_merged_lazy_context(lazy_contexts):
|
def get_merged_lazy_context(lazy_contexts):
|
||||||
|
|||||||
Reference in New Issue
Block a user