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):
22
22
...
23
23
24
24
25
+ class CustomExceptionMeta (type ):
26
+ def __instancecheck__ (cls , instance ):
27
+ return True
28
+
29
+
30
+ class CustomExceptionWithInstanceCheck (Exception , metaclass = CustomExceptionMeta ):
31
+ ...
32
+
33
+
25
34
class CustomExceptionWithArgs (Exception ):
26
35
def __init__ (self , a , b = None ):
27
36
self .a = a
@@ -149,6 +158,14 @@ def f(x: torch.Tensor):
149
158
out = f (inp )
150
159
self .assertTrue (torch .equal (out , inp + 1 ))
151
160
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
+
152
169
@make_dynamo_test
153
170
def test_propagate_exception_inside_ctx_manager (self ):
154
171
@contextlib .contextmanager
Original file line number Diff line number Diff line change @@ -1805,6 +1805,9 @@ def check_type(ty):
1805
1805
isinstance_type .__class__ .__instancecheck__ (isinstance_type , arg .value )
1806
1806
)
1807
1807
1808
+ if isinstance (arg , variables .UserDefinedExceptionClassVariable ):
1809
+ return ConstantVariable .create (isinstance (arg_type , isinstance_type ))
1810
+
1808
1811
isinstance_type_tuple : tuple [type , ...]
1809
1812
if isinstance (isinstance_type , type ) or callable (
1810
1813
# E.g. isinstance(obj, typing.Sequence)
Original file line number Diff line number Diff line change @@ -707,7 +707,6 @@ class UserDefinedExceptionClassVariable(UserDefinedClassVariable):
707
707
def fn (self ):
708
708
return self .value
709
709
710
- @property
711
710
def python_type (self ):
712
711
return self .value
713
712
You can’t perform that action at this time.
0 commit comments