File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,15 @@ class CustomException(Exception):
2222 ...
2323
2424
25+ class CustomExceptionMeta (type ):
26+ def __instancecheck__ (cls , instance ):
27+ return True
28+
29+
30+ class CustomExceptionWithInstanceCheck (Exception , metaclass = CustomExceptionMeta ):
31+ ...
32+
33+
2534class CustomExceptionWithArgs (Exception ):
2635 def __init__ (self , a , b = None ):
2736 self .a = a
@@ -149,6 +158,14 @@ def f(x: torch.Tensor):
149158 out = f (inp )
150159 self .assertTrue (torch .equal (out , inp + 1 ))
151160
161+ @make_dynamo_test
162+ def test_isinstance_CustomException (self ):
163+ assert isinstance (CustomException , type )
164+ assert not isinstance (CustomException (), type )
165+ C = CustomExceptionWithInstanceCheck
166+ assert isinstance (C , C )
167+ assert isinstance (C (), C )
168+
152169 @make_dynamo_test
153170 def test_propagate_exception_inside_ctx_manager (self ):
154171 @contextlib .contextmanager
Original file line number Diff line number Diff line change @@ -1805,6 +1805,9 @@ def check_type(ty):
18051805 isinstance_type .__class__ .__instancecheck__ (isinstance_type , arg .value )
18061806 )
18071807
1808+ if isinstance (arg , variables .UserDefinedExceptionClassVariable ):
1809+ return ConstantVariable .create (isinstance (arg_type , isinstance_type ))
1810+
18081811 isinstance_type_tuple : tuple [type , ...]
18091812 if isinstance (isinstance_type , type ) or callable (
18101813 # E.g. isinstance(obj, typing.Sequence)
Original file line number Diff line number Diff line change @@ -707,7 +707,6 @@ class UserDefinedExceptionClassVariable(UserDefinedClassVariable):
707707 def fn (self ):
708708 return self .value
709709
710- @property
711710 def python_type (self ):
712711 return self .value
713712
You can’t perform that action at this time.
0 commit comments