Skip to content

Commit 4fb302e

Browse files
suofacebook-github-bot
authored andcommitted
fix optional type promotion for classes (#21593)
Summary: Pull Request resolved: #21593 ghimport-source-id: f68730618bccf2326218e08d0a2a70171fdd8921 Differential Revision: D15741471 Pulled By: suo fbshipit-source-id: 7ac1a0f6d9d2ff4bc819caff43a7a5b6d37cbc98
1 parent a436822 commit 4fb302e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

aten/src/ATen/core/jit_type.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,12 +1380,6 @@ struct CAFFE2_API ClassType : public Type {
13801380
return false;
13811381
}
13821382

1383-
bool isSubtypeOf(const TypePtr rhs) const override {
1384-
// XXX: We do not have inheritance implemented, only types that are the
1385-
// same can subtype from each other.
1386-
return *this == *rhs;
1387-
}
1388-
13891383
std::string str() const override {
13901384
return std::string("ClassType<") + name_.name() + ">";
13911385
}

test/test_jit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16050,6 +16050,17 @@ def copy(self):
1605016050
other.stack = list(self.stack)
1605116051
return other
1605216052

16053+
def test_optional_type_promotion(self):
16054+
# should not throw
16055+
@torch.jit.script # noqa: B903
16056+
class Tree(object):
16057+
def __init__(self):
16058+
self.parent = torch.jit.annotate(Optional[Tree], None)
16059+
16060+
def add_child(self, child):
16061+
# type: (Tree) -> None
16062+
child.parent = torch.jit.annotate(Optional[Tree], self)
16063+
1605316064

1605416065
class TestLogging(JitTestCase):
1605516066
def test_bump_numeric_counter(self):

0 commit comments

Comments
 (0)