mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Merge pull request #1942 from lkh42t/inference-annotated
Support typing.Annotated inference
This commit is contained in:
@@ -32,7 +32,7 @@ _TYPE_ALIAS_TYPES = {
|
||||
'DefaultDict': 'collections.defaultdict',
|
||||
'Deque': 'collections.deque',
|
||||
}
|
||||
_PROXY_TYPES = 'Optional Union ClassVar'.split()
|
||||
_PROXY_TYPES = 'Optional Union ClassVar Annotated'.split()
|
||||
|
||||
|
||||
class TypingModuleName(NameWrapper):
|
||||
@@ -113,7 +113,7 @@ class ProxyWithGenerics(BaseTypingClassWithGenerics):
|
||||
elif string_name == 'Type':
|
||||
# The type is actually already given in the index_value
|
||||
return self._generics_manager[0]
|
||||
elif string_name == 'ClassVar':
|
||||
elif string_name in ['ClassVar', 'Annotated']:
|
||||
# For now don't do anything here, ClassVars are always used.
|
||||
return self._generics_manager[0].execute_annotation()
|
||||
|
||||
|
||||
26
test/completion/pep0593_annotations.py
Normal file
26
test/completion/pep0593_annotations.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# python >= 3.9
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
# This is just a dummy and very meaningless thing to use with to the Annotated
|
||||
# type hint
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
|
||||
def annotated_function_params(
|
||||
basic: Annotated[str, Foo()],
|
||||
obj: A,
|
||||
annotated_obj: Annotated[A, Foo()],
|
||||
):
|
||||
#? str()
|
||||
basic
|
||||
|
||||
#? A()
|
||||
obj
|
||||
|
||||
#? A()
|
||||
annotated_obj
|
||||
Reference in New Issue
Block a user