mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Remove property from python_type function (#152900)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/152900 Approved by: https://github.com/amjames, https://github.com/anijain2305 ghstack dependencies: #153070
This commit is contained in:
parent
f67eb6f8c5
commit
a4459cd4e3
|
|
@ -22,6 +22,15 @@ class CustomException(Exception):
|
|||
...
|
||||
|
||||
|
||||
class CustomExceptionMeta(type):
|
||||
def __instancecheck__(cls, instance):
|
||||
return True
|
||||
|
||||
|
||||
class CustomExceptionWithInstanceCheck(Exception, metaclass=CustomExceptionMeta):
|
||||
...
|
||||
|
||||
|
||||
class CustomExceptionWithArgs(Exception):
|
||||
def __init__(self, a, b=None):
|
||||
self.a = a
|
||||
|
|
@ -149,6 +158,14 @@ class ExceptionTests(torch._dynamo.test_case.TestCase):
|
|||
out = f(inp)
|
||||
self.assertTrue(torch.equal(out, inp + 1))
|
||||
|
||||
@make_dynamo_test
|
||||
def test_isinstance_CustomException(self):
|
||||
assert isinstance(CustomException, type)
|
||||
assert not isinstance(CustomException(), type)
|
||||
C = CustomExceptionWithInstanceCheck
|
||||
assert isinstance(C, C)
|
||||
assert isinstance(C(), C)
|
||||
|
||||
@make_dynamo_test
|
||||
def test_propagate_exception_inside_ctx_manager(self):
|
||||
@contextlib.contextmanager
|
||||
|
|
|
|||
|
|
@ -1805,6 +1805,9 @@ class BuiltinVariable(VariableTracker):
|
|||
isinstance_type.__class__.__instancecheck__(isinstance_type, arg.value)
|
||||
)
|
||||
|
||||
if isinstance(arg, variables.UserDefinedExceptionClassVariable):
|
||||
return ConstantVariable.create(isinstance(arg_type, isinstance_type))
|
||||
|
||||
isinstance_type_tuple: tuple[type, ...]
|
||||
if isinstance(isinstance_type, type) or callable(
|
||||
# E.g. isinstance(obj, typing.Sequence)
|
||||
|
|
|
|||
|
|
@ -707,7 +707,6 @@ class UserDefinedExceptionClassVariable(UserDefinedClassVariable):
|
|||
def fn(self):
|
||||
return self.value
|
||||
|
||||
@property
|
||||
def python_type(self):
|
||||
return self.value
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user