mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 01:38:36 +08:00
Improve the compiled object generation caching, which was very wrong and is ok now, but still needs improvements.
This commit is contained in:
@@ -56,11 +56,11 @@ class CompiledObject(Base):
|
|||||||
|
|
||||||
@CheckAttribute
|
@CheckAttribute
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return create(self._evaluator, self.obj.__class__, parent=self.parent)
|
return create(self._evaluator, self.obj.__class__)
|
||||||
|
|
||||||
@CheckAttribute
|
@CheckAttribute
|
||||||
def py__mro__(self):
|
def py__mro__(self):
|
||||||
return tuple(create(self._evaluator, cls, self.parent) for cls in self.obj.__mro__)
|
return tuple(create(self._evaluator, cls) for cls in self.obj.__mro__)
|
||||||
|
|
||||||
@CheckAttribute
|
@CheckAttribute
|
||||||
def py__bases__(self):
|
def py__bases__(self):
|
||||||
@@ -495,7 +495,7 @@ def compiled_objects_cache(attribute_name):
|
|||||||
def wrapper(evaluator, obj, parent=None, module=None):
|
def wrapper(evaluator, obj, parent=None, module=None):
|
||||||
cache = getattr(evaluator, attribute_name)
|
cache = getattr(evaluator, attribute_name)
|
||||||
# Do a very cheap form of caching here.
|
# Do a very cheap form of caching here.
|
||||||
key = id(obj)
|
key = id(obj), id(parent)
|
||||||
try:
|
try:
|
||||||
return cache[key][0]
|
return cache[key][0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -519,10 +519,14 @@ def create(evaluator, obj, parent=None, module=None):
|
|||||||
A very weird interface class to this module. The more options provided the
|
A very weird interface class to this module. The more options provided the
|
||||||
more acurate loading compiled objects is.
|
more acurate loading compiled objects is.
|
||||||
"""
|
"""
|
||||||
if parent is None and not inspect.ismodule(obj):
|
if inspect.ismodule(obj):
|
||||||
parent = create(evaluator, _builtins)
|
if parent is not None:
|
||||||
|
# Modules don't have parents, be careful with caching: recurse.
|
||||||
|
return create(evaluator, obj)
|
||||||
|
else:
|
||||||
|
if parent is None and obj != _builtins:
|
||||||
|
return create(evaluator, obj, create(evaluator, _builtins))
|
||||||
|
|
||||||
if not inspect.ismodule(obj):
|
|
||||||
faked = fake.get_faked(module and module.obj, obj)
|
faked = fake.get_faked(module and module.obj, obj)
|
||||||
if faked is not None:
|
if faked is not None:
|
||||||
faked.parent = parent
|
faked.parent = parent
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ understand them with Jedi.
|
|||||||
To add a new implementation, create a function and add it to the
|
To add a new implementation, create a function and add it to the
|
||||||
``_implemented`` dict at the bottom of this module.
|
``_implemented`` dict at the bottom of this module.
|
||||||
|
|
||||||
|
Note that this module exists only to implement very specific functionality in
|
||||||
|
the standard library. The usual way to understand the standard library is the
|
||||||
|
compiled module that returns the types for C-builtins.
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
@@ -198,7 +201,10 @@ def builtins_isinstance(evaluator, objects, types, arguments):
|
|||||||
else:
|
else:
|
||||||
_, nodes = list(arguments.unpack())[1]
|
_, nodes = list(arguments.unpack())[1]
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
analysis.add(evaluator, 'type-error-isinstance', node)
|
message = 'TypeError: isinstance() arg 2 must be a ' \
|
||||||
|
'class, type, or tuple of classes and types, ' \
|
||||||
|
'not %s.' % cls_or_tup
|
||||||
|
analysis.add(evaluator, 'type-error-isinstance', node, message)
|
||||||
|
|
||||||
return set(compiled.create(evaluator, x) for x in bool_results)
|
return set(compiled.create(evaluator, x) for x in bool_results)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user