Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIT] add support for torch.jit.Final in python 3.6 #47393

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions test/jit/test_recursive_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unittest
import os
import sys
import typing
Expand Down Expand Up @@ -159,7 +158,6 @@ def a(x):
# Make sure that no entries are left over from the previous failure
FileCheck().check_count("is being compiled", 2).run(str(e))

@unittest.skipIf(sys.version_info[:2] < (3, 7), "Class annotations are a thing in > 3.5, need to fix for < 3.7")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment was out of date? Not totally sure, but this test now passes for python3.6 and python3.7 and checks the functionality of Final

def test_constants_with_final(self):
class M1(torch.nn.Module):
x : torch.jit.Final[int]
Expand Down
2 changes: 1 addition & 1 deletion torch/_jit_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def is_rref(ann):

def is_final(ann):
return ann.__module__ in {'typing', 'typing_extensions'} and \
(getattr(ann, '__origin__', None) is Final)
(getattr(ann, '__origin__', None) is Final or isinstance(ann, type(Final)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional:

Can you say a bit more about why this change is needed (in PR description)? I am curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added :)


# allows BroadcastingList instance to be subscriptable
class BroadcastingListCls(object):
Expand Down