Add parsing logic for Tuple[()] annotation (#58340)

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

Test Plan: Imported from OSS

Reviewed By: jamesr66a

Differential Revision: D28459502

Pulled By: ansley

fbshipit-source-id: 4bb188448d66269b42b068858b895debac86e9ee
This commit is contained in:
Ansley Ussery
2021-05-25 12:11:15 -07:00
committed by Facebook GitHub Bot
parent b9d1ad9c78
commit 5268b5a29a
9 changed files with 63 additions and 5 deletions

View File

@ -61,6 +61,11 @@ def createResolutionCallbackFromEnv(lookup_base):
while i < len(expr) and expr[i] not in (',', '[', ']'):
i += 1
# Special case logic for the empty Tuple as a subscript (used
# in the type annotation `Tuple[()]`)
if expr[:i] == '()':
return (), i
base = lookupInModule(expr[:i].strip(), module)
assert base is not None, f"Unresolvable type {expr[:i]}"
if i == len(expr) or expr[i] != '[':