From 21f1df18b6d74b7eb2fdbc30dc3cc2b03d2a7fca Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 14 Jun 2020 18:07:54 +0200 Subject: [PATCH] Fix some issues with sub class matching, fixes #1560 --- jedi/inference/gradual/base.py | 9 +++++++-- test/completion/pep0484_generic_passthroughs.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/jedi/inference/gradual/base.py b/jedi/inference/gradual/base.py index 44564f65..2c0ac993 100644 --- a/jedi/inference/gradual/base.py +++ b/jedi/inference/gradual/base.py @@ -138,8 +138,13 @@ class DefineGenericBaseClass(LazyValueWrapper): any( # TODO why is this ordering the correct one? cls2.is_same_class(cls1) - for cls1 in class_set1 - for cls2 in class_set2 + # TODO I'm still not sure gather_annotation_classes is a good + # idea. They are essentially here to avoid comparing Tuple <=> + # tuple and instead compare tuple <=> tuple, but at the moment + # the whole `is_same_class` and `is_sub_class` matching is just + # not in the best shape. + for cls1 in class_set1.gather_annotation_classes() + for cls2 in class_set2.gather_annotation_classes() ) for class_set1, class_set2 in zip(given_params1, given_params2) ) diff --git a/test/completion/pep0484_generic_passthroughs.py b/test/completion/pep0484_generic_passthroughs.py index 4fccc5ed..ba2a8bcc 100644 --- a/test/completion/pep0484_generic_passthroughs.py +++ b/test/completion/pep0484_generic_passthroughs.py @@ -1,5 +1,5 @@ # python >= 3.4 -from typing import Any, Iterable, List, Sequence, Tuple, TypeVar, Union +from typing import Any, Iterable, List, Sequence, Tuple, TypeVar, Union, Generic T = TypeVar('T') U = TypeVar('U') @@ -142,3 +142,17 @@ CustomList[str]().get_first() typed_fully_generic_passthrough(CustomList[str]())[0] #? typed_list_generic_passthrough(CustomList[str])[0] + + +class That(Generic[T]): + def __init__(self, items: List[Tuple[str, T]]) -> None: + pass + + def get(self) -> T: + pass + +inst = That([("abc", 2)]) + +# No completions here, but should have completions for `int` +#? int() +inst.get()