1
0
forked from VimPlug/jedi

Ignore Final/ClassVar if they don't have a generic assignment

This commit is contained in:
Dave Halter
2026-04-28 17:05:43 +02:00
parent 6473ddc28c
commit 75f1d064d5
4 changed files with 58 additions and 20 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ _TYPE_ALIAS_TYPES = {
'Deque': 'collections.deque',
}
_PROXY_TYPES = ['Optional', 'Union', 'ClassVar', 'Annotated', 'Final']
_IGNORE_ANNOTATION_PARTS = ['ClassVar', 'Annotated', 'Final']
IGNORE_ANNOTATION_PARTS = ['ClassVar', 'Annotated', 'Final']
class TypingModuleName(NameWrapper):
@@ -115,7 +115,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 in _IGNORE_ANNOTATION_PARTS:
elif string_name in IGNORE_ANNOTATION_PARTS:
# For now don't do anything here, ClassVars are always used.
return self._generics_manager[0].execute_annotation()
+12 -3
View File
@@ -30,6 +30,7 @@ from jedi.inference.names import TreeNameDefinition
from jedi.inference.context import CompForContext
from jedi.inference.value.decorator import Decoratee
from jedi.plugins import plugin_manager
from jedi.inference.gradual.typing import ProxyTypingValue, IGNORE_ANNOTATION_PARTS
operator_to_magic_method = {
'+': '__add__',
@@ -701,16 +702,24 @@ def tree_name_to_values(inference_state, context, tree_name):
correct_scope = parser_utils.get_parent_scope(name) == context.tree_node
ann_assign = expr_stmt.children[1]
if correct_scope:
found_annotation = True
if (
(ann_assign.children[1].type == 'name')
and (ann_assign.children[1].value == tree_name.value)
and context.parent_context
):
context = context.parent_context
value_set |= annotation.infer_annotation(
found = annotation.infer_annotation(
context, expr_stmt.children[1].children[1]
).execute_annotation()
)
set_found_annotation = True
if len(found) == 1:
first = next(iter(found))
set_found_annotation = not (
isinstance(first, ProxyTypingValue)
and first.name.string_name in IGNORE_ANNOTATION_PARTS
)
found_annotation = set_found_annotation
value_set |= found.execute_annotation()
if found_annotation:
return value_set