1
0
forked from VimPlug/jedi

Properly convert compiled values to generic classes

This commit is contained in:
Dave Halter
2020-01-10 15:07:11 +01:00
parent cac73f2d44
commit 3ba68b5bc6
5 changed files with 74 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import sys
import operator as op
from collections import namedtuple
import warnings
import re
from jedi._compatibility import unicode, is_py3, builtins, \
py_version, force_unicode
@@ -491,10 +492,15 @@ class DirectObjectAccess(object):
if sys.version_info < (3, 5):
return None, ()
import typing
args = typing.get_args(self._obj)
origin = typing.get_origin(self._obj)
name = None if origin is None else str(origin)
name = None
args = ()
if safe_getattr(self._obj, '__module__', default='') == 'typing':
m = re.match(r'typing.(\w+)\[', repr(self._obj))
if m is not None:
name = m.group(1)
import typing
args = typing.get_args(self._obj)
return name, tuple(self._create_access_path(arg) for arg in args)
def needs_type_completions(self):

View File

@@ -273,9 +273,20 @@ class CompiledObject(Value):
return ValueSet([self])
name, args = self.access_handle.get_annotation_name_and_args()
arguments = [create_from_access_path(self.inference_state, path) for path in args]
if name == 'typing.Union':
arguments = [
ValueSet([create_from_access_path(self.inference_state, path)])
for path in args
]
if name == 'Union':
return ValueSet.from_sets(arg.execute_annotation() for arg in arguments)
elif name:
# While with_generics only exists on very specific objects, we
# should probably be fine, because we control all the typing
# objects.
return ValueSet([
v.with_generics(arguments)
for v in self.inference_state.typing_module.py__getattribute__(name)
]).execute_annotation()
return super(CompiledObject, self).execute_annotation()
def negate(self):