mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +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.
|
||||
"""
|
||||
|
||||
NO_DEFAULT = object()
|
||||
|
||||
|
||||
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:
|
||||
@@ -32,6 +34,7 @@ def memoize_default(default=None, evaluator_is_first_arg=False, second_arg_is_ev
|
||||
if key in memo:
|
||||
return memo[key]
|
||||
else:
|
||||
if default is not NO_DEFAULT:
|
||||
memo[key] = default
|
||||
rv = function(obj, *args, **kwargs)
|
||||
memo[key] = rv
|
||||
|
||||
@@ -27,7 +27,7 @@ from jedi.evaluate import helpers
|
||||
from jedi import settings
|
||||
from jedi.common import source_to_unicode
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate.cache import memoize_default
|
||||
from jedi.evaluate.cache import memoize_default, NO_DEFAULT
|
||||
|
||||
|
||||
class ModuleNotFound(Exception):
|
||||
@@ -290,7 +290,7 @@ class _Importer(object):
|
||||
return evaluator.follow_path(iter(rest), [scope], scope)
|
||||
return [scope]
|
||||
|
||||
@memoize_default()
|
||||
@memoize_default(NO_DEFAULT)
|
||||
def follow_file_system(self):
|
||||
if self.file_path:
|
||||
sys_path_mod = list(self.sys_path_with_modifications())
|
||||
|
||||
@@ -303,3 +303,17 @@ recurse_class1.C.a
|
||||
# github #239 RecursionError
|
||||
#? ['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