mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
memoize problems with defaults in combination with raised exceptions
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
- ``CachedMetaClass`` uses ``memoize_default`` to do the same with classes.
|
- ``CachedMetaClass`` uses ``memoize_default`` to do the same with classes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
NO_DEFAULT = object()
|
||||||
|
|
||||||
|
|
||||||
def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_evaluator=False):
|
def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_evaluator=False):
|
||||||
""" This is a typical memoization decorator, BUT there is one difference:
|
""" This is a typical memoization decorator, BUT there is one difference:
|
||||||
@@ -32,7 +34,8 @@ def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_ev
|
|||||||
if key in memo:
|
if key in memo:
|
||||||
return memo[key]
|
return memo[key]
|
||||||
else:
|
else:
|
||||||
memo[key] = default
|
if default is not NO_DEFAULT:
|
||||||
|
memo[key] = default
|
||||||
rv = function(obj, *args, **kwargs)
|
rv = function(obj, *args, **kwargs)
|
||||||
memo[key] = rv
|
memo[key] = rv
|
||||||
return rv
|
return rv
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from jedi.evaluate import helpers
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.common import source_to_unicode
|
from jedi.common import source_to_unicode
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default, NO_DEFAULT
|
||||||
|
|
||||||
|
|
||||||
class ModuleNotFound(Exception):
|
class ModuleNotFound(Exception):
|
||||||
@@ -290,7 +290,7 @@ class _Importer(object):
|
|||||||
return evaluator.follow_path(iter(rest), [scope], scope)
|
return evaluator.follow_path(iter(rest), [scope], scope)
|
||||||
return [scope]
|
return [scope]
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default(NO_DEFAULT)
|
||||||
def follow_file_system(self):
|
def follow_file_system(self):
|
||||||
if self.file_path:
|
if self.file_path:
|
||||||
sys_path_mod = list(self.sys_path_with_modifications())
|
sys_path_mod = list(self.sys_path_with_modifications())
|
||||||
|
|||||||
@@ -303,3 +303,17 @@ recurse_class1.C.a
|
|||||||
# github #239 RecursionError
|
# github #239 RecursionError
|
||||||
#? ['a']
|
#? ['a']
|
||||||
recurse_class1.C().a
|
recurse_class1.C().a
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# Jedi debugging
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
# memoizing issues (check git history for the fix)
|
||||||
|
import not_existing_import
|
||||||
|
|
||||||
|
if not_existing_import:
|
||||||
|
a = not_existing_import
|
||||||
|
else:
|
||||||
|
a = not_existing_import
|
||||||
|
#?
|
||||||
|
a
|
||||||
|
|||||||
Reference in New Issue
Block a user