1
0
forked from VimPlug/jedi

Fix the typing module issues in Python 3.6.

This commit is contained in:
Dave Halter
2017-01-02 15:01:12 +01:00
parent 5b9e5f96aa
commit 5d071ede8c
2 changed files with 8 additions and 3 deletions
+2 -1
View File
@@ -654,6 +654,7 @@ def py__iter__types(evaluator, types, node=None):
def py__getitem__(evaluator, context, types, trailer): def py__getitem__(evaluator, context, types, trailer):
from jedi.evaluate.representation import ClassContext from jedi.evaluate.representation import ClassContext
from jedi.evaluate.instance import TreeInstance
result = set() result = set()
trailer_op, node, trailer_cl = trailer.children trailer_op, node, trailer_cl = trailer.children
@@ -663,7 +664,7 @@ def py__getitem__(evaluator, context, types, trailer):
# special case: PEP0484 typing module, see # special case: PEP0484 typing module, see
# https://github.com/davidhalter/jedi/issues/663 # https://github.com/davidhalter/jedi/issues/663
for typ in list(types): for typ in list(types):
if isinstance(typ, ClassContext): if isinstance(typ, (ClassContext, TreeInstance)):
typing_module_types = pep0484.py__getitem__(context, typ, node) typing_module_types = pep0484.py__getitem__(context, typ, node)
if typing_module_types is not None: if typing_module_types is not None:
types.remove(typ) types.remove(typ)
+6 -2
View File
@@ -139,9 +139,13 @@ def py__getitem__(context, typ, node):
type_name = typ.name.string_name type_name = typ.name.string_name
# hacked in Union and Optional, since it's hard to do nicely in parsed code # hacked in Union and Optional, since it's hard to do nicely in parsed code
if type_name == "Union": if type_name in ("Union", '_Union'):
# In Python 3.6 it's still called typing.Union but it's an instance
# called _Union.
return unite(context.eval_node(node) for node in nodes) return unite(context.eval_node(node) for node in nodes)
if type_name == "Optional": if type_name in ("Optional", '_Optional'):
# Here we have the same issue like in Union. Therefore we also need to
# check for the instance typing._Optional (Python 3.6).
return context.eval_node(nodes[0]) return context.eval_node(nodes[0])
from jedi.evaluate.representation import ModuleContext from jedi.evaluate.representation import ModuleContext