@@ -91,17 +91,14 @@ def _infer_value_type_with_auto_fallback(
9191 # Enums in stubs may have ... instead of actual values. If `_value_` is annotated
9292 # (manually or inherited from IntEnum, for example), it is a more reasonable guess
9393 # than literal ellipsis type.
94- source_module = ctx .api .modules [ctx .type .type .fullname .rsplit ("." , 1 )[0 ]]
9594 if (
96- source_module . is_stub
95+ _is_defined_in_stub ( ctx )
9796 and isinstance (proper_type , Instance )
9897 and proper_type .type .fullname in ELLIPSIS_TYPE_NAMES
98+ and isinstance (ctx .type , Instance )
9999 ):
100- if (
101- isinstance (ctx .type , Instance )
102- and (value_type := ctx .type .type .get ("_value_" ))
103- and isinstance (var := value_type .node , Var )
104- ):
100+ value_type = ctx .type .type .get ("_value_" )
101+ if value_type is not None and isinstance (var := value_type .node , Var ):
105102 return var .type
106103 return proper_type
107104 if not (isinstance (proper_type , Instance ) and proper_type .type .fullname == "enum.auto" ):
@@ -131,6 +128,13 @@ def _infer_value_type_with_auto_fallback(
131128 return ctx .default_attr_type
132129
133130
131+ def _is_defined_in_stub (ctx : mypy .plugin .AttributeContext ) -> bool :
132+ return (
133+ isinstance (ctx .type , Instance )
134+ and ctx .api .modules [ctx .type .type .fullname .rsplit ("." , 1 )[0 ]].is_stub
135+ )
136+
137+
134138def _implements_new (info : TypeInfo ) -> bool :
135139 """Check whether __new__ comes from enum.Enum or was implemented in a
136140 subclass. In the latter case, we must infer Any as long as mypy can't infer
0 commit comments