@@ -858,8 +858,31 @@ def verify_decorator(
858
858
def verify_typealias (
859
859
stub : nodes .TypeAlias , runtime : MaybeMissing [Any ], object_path : List [str ]
860
860
) -> Iterator [Error ]:
861
- if False :
862
- yield None
861
+ if isinstance (runtime , Missing ):
862
+ # ignore type aliases that don't have a runtime counterpart
863
+ return
864
+ stub_target = mypy .types .get_proper_type (stub .target )
865
+ if isinstance (stub_target , mypy .types .Instance ):
866
+ yield from verify (stub_target .type , runtime , object_path )
867
+ return
868
+ if isinstance (stub_target , mypy .types .UnionType ):
869
+ if not getattr (runtime , "__origin__" , None ) is Union :
870
+ yield Error (object_path , "is not a Union" , stub , runtime , stub_desc = str (stub_target ))
871
+ # could check Union contents here...
872
+ return
873
+ if isinstance (stub_target , mypy .types .TupleType ):
874
+ if tuple not in getattr (runtime , "__mro__" , ()):
875
+ yield Error (
876
+ object_path , "is not a subclass of tuple" , stub , runtime ,
877
+ stub_desc = str (stub_target )
878
+ )
879
+ # could check Tuple contents here...
880
+ return
881
+ if isinstance (stub_target , mypy .types .AnyType ):
882
+ return
883
+ yield Error (
884
+ object_path , "is not a recognised type alias" , stub , runtime , stub_desc = str (stub_target )
885
+ )
863
886
864
887
865
888
SPECIAL_DUNDERS = ("__init__" , "__new__" , "__call__" , "__init_subclass__" , "__class_getitem__" )
@@ -887,10 +910,11 @@ def is_probably_a_function(runtime: Any) -> bool:
887
910
def safe_inspect_signature (runtime : Any ) -> Optional [inspect .Signature ]:
888
911
try :
889
912
return inspect .signature (runtime )
890
- except ( ValueError , RuntimeError , TypeError ) :
891
- # inspect.signature throws sometimes
913
+ except Exception :
914
+ # inspect.signature throws ValueError all the time
892
915
# catch RuntimeError because of https://bugs.python.org/issue39504
893
916
# catch TypeError because of https://github.com/python/typeshed/pull/5762
917
+ # catch AttributeError because of inspect.signature(_curses.window.border)
894
918
return None
895
919
896
920
0 commit comments