@@ -166,10 +166,8 @@ def __init__(self,
166166 self .is_package_init_file = False
167167
168168 # TODO (incomplete):
169- # from m import *
170169 # await
171170 # protocols
172- # metaclasses
173171
174172 def visit_mypy_file (self , o : MypyFile ) -> None :
175173 self .scope .enter_file (o .fullname ())
@@ -232,6 +230,8 @@ def process_type_info(self, info: TypeInfo) -> None:
232230 self .add_type_dependencies (info .tuple_type , target = make_trigger (target ))
233231 if info .typeddict_type :
234232 self .add_type_dependencies (info .typeddict_type , target = make_trigger (target ))
233+ if info .declared_metaclass :
234+ self .add_type_dependencies (info .declared_metaclass , target = make_trigger (target ))
235235 # TODO: Add dependencies based on remaining TypeInfo attributes.
236236 self .add_type_alias_deps (self .scope .current_target ())
237237 for name , node in info .names .items ():
@@ -530,7 +530,6 @@ def add_operator_method_dependency_for_type(self, typ: Type, method: str) -> Non
530530 # Note that operator methods can't be (non-metaclass) methods of type objects
531531 # (that is, TypeType objects or Callables representing a type).
532532 # TODO: TypedDict
533- # TODO: metaclasses
534533 if isinstance (typ , TypeVarType ):
535534 typ = typ .upper_bound
536535 if isinstance (typ , TupleType ):
@@ -541,6 +540,11 @@ def add_operator_method_dependency_for_type(self, typ: Type, method: str) -> Non
541540 elif isinstance (typ , UnionType ):
542541 for item in typ .items :
543542 self .add_operator_method_dependency_for_type (item , method )
543+ elif isinstance (typ , FunctionLike ) and typ .is_type_obj ():
544+ self .add_operator_method_dependency_for_type (typ .fallback , method )
545+ elif isinstance (typ , TypeType ):
546+ if isinstance (typ .item , Instance ) and typ .item .type .metaclass_type is not None :
547+ self .add_operator_method_dependency_for_type (typ .item .type .metaclass_type , method )
544548
545549 def visit_generator_expr (self , e : GeneratorExpr ) -> None :
546550 super ().visit_generator_expr (e )
@@ -613,15 +617,21 @@ def attribute_triggers(self, typ: Type, name: str) -> List[str]:
613617 return [make_trigger (member )]
614618 elif isinstance (typ , FunctionLike ) and typ .is_type_obj ():
615619 member = '%s.%s' % (typ .type_object ().fullname (), name )
616- return [make_trigger (member )]
620+ triggers = [make_trigger (member )]
621+ triggers .extend (self .attribute_triggers (typ .fallback , name ))
622+ return triggers
617623 elif isinstance (typ , UnionType ):
618624 targets = []
619625 for item in typ .items :
620626 targets .extend (self .attribute_triggers (item , name ))
621627 return targets
622628 elif isinstance (typ , TypeType ):
623- # TODO: Metaclass attribute lookup
624- return self .attribute_triggers (typ .item , name )
629+ triggers = self .attribute_triggers (typ .item , name )
630+ if isinstance (typ .item , Instance ) and typ .item .type .metaclass_type is not None :
631+ triggers .append (make_trigger ('%s.%s' %
632+ (typ .item .type .metaclass_type .type .fullname (),
633+ name )))
634+ return triggers
625635 else :
626636 return []
627637
0 commit comments