8000 Remove `property` from python_type function (#152900) · pytorch/pytorch@a4459cd · GitHub
[go: up one dir, main page]

Skip to content

Commit a4459cd

Browse files
guilhermeleobaspytorchmergebot
authored andcommitted
Remove property from python_type function (#152900)
Pull Request resolved: #152900 Approved by: https://github.com/amjames, https://github.com/anijain2305 ghstack dependencies: #153070
1 parent f67eb6f commit a4459cd

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

test/dynamo/test_exceptions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
2534
class 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

torch/_dynamo/variables/builtin.py

Copy file name to clipboard
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

torch/_dynamo/variables/user_defined.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)
0