-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Monkey patch Jedi 0.10.0 for numpydoc #4121
Merged
+130
−100
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
af0d270
Numpydoc monkey patch for jedi 0.10.0
bcolsen d233969
Code clean up and PEP8
bcolsen a252d1c
Remove jedi 0.9.0 pinning
bcolsen 113f5ef
cache fix
bcolsen 5879b89
Testing: Install Jedi with pip in CircleCI to use 0.10.0
ccordoba12 f9fe24d
disable cache
bcolsen 370052b
Merge branch 'patch_jedi_10' of https://github.com/bcolsen/spyder int…
bcolsen 4e6a7f6
Change the tests?
bcolsen 8ff7bfd
Update with 3.1.x
ccordoba12 c34b99d
Docs: Fix link to Jedi webpage
ccordoba12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,11 @@ def apply(): | |
See [1] and [2] module docstring.""" | ||
from spyder.utils.programs import is_module_installed | ||
if is_module_installed('jedi', '=0.9.0'): | ||
if (is_module_installed('jedi', '=0.9.0') or | ||
is_module_installed('jedi', '=0.10.0')): | ||
import jedi | ||
else: | ||
raise ImportError("jedi %s can't be patched" % jedi.__version__) | ||
raise ImportError("jedi not =0.9.0 or 0.10.0, can't be patched") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# [1] Adding numpydoc type returns to docstrings | ||
from spyder.utils.introspection import numpy_docstr | ||
|
@@ -36,11 +37,10 @@ def apply(): | |
|
||
# [2] Adding type returns for compiled objects in jedi | ||
# Patching jedi.evaluate.compiled.CompiledObject... | ||
from jedi.evaluate.compiled import ( | ||
CompiledObject, builtin, _create_from_name, debug) | ||
if is_module_installed('jedi', '=0.9.0'): | ||
from jedi.evaluate.compiled import (builtin, _create_from_name, | ||
debug, CompiledObject) | ||
|
||
class CompiledObject(CompiledObject): | ||
# ...adding docstrings int _execute_function... | ||
def _execute_function(self, evaluator, params): | ||
if self.type != 'funcdef': | ||
return | ||
|
@@ -58,87 +58,110 @@ def _execute_function(self, evaluator, params): | |
except AttributeError: | ||
continue | ||
else: | ||
if isinstance(bltn_obj, CompiledObject) and bltn_obj.obj is None: | ||
if (isinstance(bltn_obj, CompiledObject) and | ||
bltn_obj.obj is None): | ||
# We want everything except None. | ||
continue | ||
for result in evaluator.execute(bltn_obj, params): | ||
yield result | ||
|
||
# ...docstrings needs a raw_doc property | ||
@property | ||
def raw_doc(self): | ||
try: | ||
doc = unicode(self.doc) | ||
except NameError: # python 3 | ||
doc = self.doc | ||
return doc | ||
|
||
jedi.evaluate.compiled.CompiledObject = CompiledObject | ||
|
||
# [3] Fixing introspection for matplotlib Axes objects | ||
# Patching jedi.evaluate.precedence... | ||
from jedi.evaluate.precedence import tree, calculate | ||
|
||
def calculate_children(evaluator, children): | ||
""" | ||
Calculate a list of children with operators. | ||
""" | ||
iterator = iter(children) | ||
types = evaluator.eval_element(next(iterator)) | ||
for operator in iterator: | ||
try:# PATCH: Catches StopIteration error | ||
right = next(iterator) | ||
if tree.is_node(operator, 'comp_op'): # not in / is not | ||
operator = ' '.join(str(c.value) for c in operator.children) | ||
|
||
# handle lazy evaluation of and/or here. | ||
if operator in ('and', 'or'): | ||
left_bools = set([left.py__bool__() for left in types]) | ||
if left_bools == set([True]): | ||
if operator == 'and': | ||
types = evaluator.eval_element(right) | ||
elif left_bools == set([False]): | ||
if operator != 'and': | ||
types = evaluator.eval_element(right) | ||
# Otherwise continue, because of uncertainty. | ||
else: # Code for Jedi 0.10.0 | ||
from jedi.evaluate.compiled import debug, create | ||
from jedi._compatibility import builtins as _builtins | ||
|
||
def _execute_function(self, params): | ||
from spyder.utils.introspection import numpy_docstr | ||
if self.type != 'funcdef': | ||
return | ||
types = set([]) | ||
types |= set(numpy_docstr.find_return_types(self.parent_context, | ||
self)) | ||
debug.dbg('docstrings type return: %s in %s', types, self) | ||
for name in self._parse_function_doc()[1].split(): | ||
try: | ||
bltn_obj = getattr(_builtins, name) | ||
except AttributeError: | ||
continue | ||
else: | ||
types = calculate(evaluator, types, operator, | ||
evaluator.eval_element(right)) | ||
except StopIteration: | ||
debug.warning('calculate_children StopIteration %s', types) | ||
debug.dbg('calculate_children types %s', types) | ||
return types | ||
|
||
jedi.evaluate.precedence.calculate_children = calculate_children | ||
|
||
# [4] Fixing introspection for matplotlib Axes objects | ||
# Patching jedi.evaluate.precedence... | ||
from jedi.evaluate.representation import ( | ||
InstanceName, Instance, compiled, FunctionExecution, InstanceElement) | ||
|
||
def get_instance_el(evaluator, instance, var, is_class_var=False): | ||
""" | ||
Returns an InstanceElement if it makes sense, otherwise leaves the object | ||
untouched. | ||
Basically having an InstanceElement is context information. That is needed | ||
in quite a lot of cases, which includes Nodes like ``power``, that need to | ||
know where a self name comes from for example. | ||
""" | ||
if isinstance(var, tree.Name): | ||
parent = get_instance_el(evaluator, instance, var.parent, is_class_var) | ||
return InstanceName(var, parent) | ||
# PATCH: compiled objects can be None | ||
elif var is None: | ||
return var | ||
elif var.type != 'funcdef' \ | ||
and isinstance(var, (Instance, compiled.CompiledObject, tree.Leaf, | ||
tree.Module, FunctionExecution)): | ||
return var | ||
|
||
var = evaluator.wrap(var) | ||
return InstanceElement(evaluator, instance, var, is_class_var) | ||
|
||
jedi.evaluate.representation.get_instance_el = get_instance_el | ||
if bltn_obj is None: | ||
# We want to evaluate everything except None. | ||
continue | ||
bltn_obj = create(self.evaluator, bltn_obj) | ||
types |= set(self.evaluator.execute(bltn_obj, params)) | ||
for result in types: | ||
yield result | ||
|
||
jedi.evaluate.compiled.CompiledObject._execute_function = _execute_function | ||
|
||
if is_module_installed('jedi', '=0.9.0'): | ||
# [3] Fixing introspection for matplotlib Axes objects | ||
# Patching jedi.evaluate.precedence... | ||
from jedi.evaluate.precedence import tree, calculate | ||
|
||
def calculate_children(evaluator, children): | ||
""" | ||
Calculate a list of children with operators. | ||
""" | ||
iterator = iter(children) | ||
types = evaluator.eval_element(next(iterator)) | ||
for operator in iterator: | ||
try: # PATCH: Catches StopIteration error | ||
right = next(iterator) | ||
if tree.is_node(operator, 'comp_op'): # not in / is not | ||
operator = ' '.join(str(c.value) for c in | ||
operator.children) | ||
|
||
# handle lazy evaluation of and/or here. | ||
if operator in ('and', 'or'): | ||
left_bools = set([left.py__bool__() for left in types]) | ||
if left_bools == set([True]): | ||
if operator == 'and': | ||
types = evaluator.eval_element(right) | ||
elif left_bools == set([False]): | ||
if operator != 'and': | ||
types = evaluator.eval_element(right) | ||
# Otherwise continue, because of uncertainty. | ||
else: | ||
types = calculate(evaluator, types, operator, | ||
evaluator.eval_element(right)) | ||
except StopIteration: | ||
debug.warning('calculate_children StopIteration %s', types) | ||
debug.dbg('calculate_children types %s', types) | ||
return types | ||
|
||
jedi.evaluate.precedence.calculate_children = calculate_children | ||
|
||
# [4] Fixing introspection for matplotlib Axes objects | ||
# Patching jedi.evaluate.precedence... | ||
from jedi.evaluate.representation import (InstanceName, Instance, | ||
compiled, FunctionExecution, | ||
InstanceElement) | ||
|
||
def get_instance_el(evaluator, instance, var, is_class_var=False): | ||
""" | ||
Returns an InstanceElement if it makes sense, otherwise leaves the | ||
object untouched. | ||
Basically having an InstanceElement is context information. That is | ||
needed in quite a lot of cases, which includes Nodes like | ||
``power``, that need to know where a self name comes from for | ||
example. | ||
""" | ||
if isinstance(var, tree.Name): | ||
parent = get_instance_el(evaluator, instance, var.parent, | ||
is_class_var) | ||
return InstanceName(var, parent) | ||
# PATCH: compiled objects can be None | ||
elif var is None: | ||
return var | ||
elif var.type != 'funcdef' \ | ||
and isinstance(var, (Instance, compiled.CompiledObject, | ||
tree.Leaf, tree.Module, FunctionExecution)): | ||
return var | ||
|
||
var = evaluator.wrap(var) | ||
return InstanceElement(evaluator, instance, var, is_class_var) | ||
|
||
jedi.evaluate.representation.get_instance_el = get_instance_el | ||
|
||
return jedi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember that I wrote it that way so that when Jedi 0.11.0 comes out my patching won't thrash it(like it did when 0.10.0 came out). I am also hoping not to have to patch 0.11.0 :-)
I can still make the change if you think that's best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fair enough ;-) Please leave it as it is then.