Remove a use of exec (#35624)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/35624

Python 2 has reached end-of-life and is no longer supported by PyTorch.
This test case is valid syntax in Python 3.

Test Plan: CI

Differential Revision: D20842877

Pulled By: dreiss

fbshipit-source-id: 856e72171496aa1d517f2f27a8a5066462cf4f76
This commit is contained in:
David Reiss
2020-05-14 10:03:34 -07:00
committed by Facebook GitHub Bot
parent 7f7fdb1013
commit 2f4da7c00c

View File

@ -162,12 +162,9 @@ class TestNamedTensor(TestCase):
self.assertTrue(fully_named.has_names())
def test_py3_ellipsis(self):
# Need to exec or else flake8 will complain about invalid python 2.
tensor = torch.randn(2, 3, 5, 7)
scope = {'tensor': tensor}
code_str = "output = tensor.refine_names('N', ..., 'C')"
exec(code_str, globals(), scope)
self.assertEqual(scope['output'].names, ['N', None, None, 'C'])
output = tensor.refine_names('N', ..., 'C')
self.assertEqual(output.names, ['N', None, None, 'C'])
def test_refine_names(self):
# Unnamed tensor -> Unnamed tensor