1
0
forked from VimPlug/jedi

Add support for generic optional parameters (#1559)

* Add support for generic optional parameters

* Tests for passing non-optional arguments to optional parameters

* Remove now-redundant is_class_value handling

This parameter has since been removed from infer_type_vars methods,
much simplifying the code.
This commit is contained in:
Peter Law
2020-05-15 18:56:03 +01:00
committed by GitHub
parent d4aa583e16
commit 43806f8668
2 changed files with 67 additions and 0 deletions
+18
View File
@@ -145,6 +145,24 @@ class TypingClassWithIndex(BaseTypingClassWithGenerics):
generics_manager
)
def infer_type_vars(self, value_set):
annotation_generics = self.get_generics()
if not annotation_generics:
return {}
annotation_name = self.py__name__()
if annotation_name == 'Optional':
# Optional[T] is equivalent to Union[T, None]. In Jedi unions
# are represented by members within a ValueSet, so we extract
# the T from the Optional[T] by removing the None value.
none = builtin_from_name(self.inference_state, u'None')
return annotation_generics[0].infer_type_vars(
value_set.filter(lambda x: x != none),
)
return {}
class ProxyTypingValue(BaseTypingValue):
index_class = TypingClassWithIndex