[BE] Import Literal, Protocol, and Final from standard library typing as of Python 3.8+ (#94490)

Changes:

1. `typing_extensions -> typing-extentions` in dependency. Use dash rather than underline to fit the [PEP 503: Normalized Names](https://peps.python.org/pep-0503/#normalized-names) convention.

```python
import re

def normalize(name):
    return re.sub(r"[-_.]+", "-", name).lower()
```

2. Import `Literal`, `Protocal`, and `Final` from standard library as of Python 3.8+
3. Replace `Union[Literal[XXX], Literal[YYY]]` to `Literal[XXX, YYY]`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94490
Approved by: https://github.com/ezyang, https://github.com/albanD
This commit is contained in:
Xuehai Pan
2023-02-09 19:17:46 +00:00
committed by PyTorch MergeBot
parent 527b646f4b
commit 69e0bda999
47 changed files with 76 additions and 102 deletions

View File

@ -25,7 +25,7 @@ from typing import (
Union,
)
from typing_extensions import Literal
from typing_extensions import Literal # Python 3.8+
from torchgen.code_template import CodeTemplate
@ -62,8 +62,8 @@ class YamlLoader(Loader):
# code we want.
#
# This is an OPEN enum (we may add more cases to it in the future), so be sure
# to explicitly specify with Union[Literal[Target.XXX]] what targets are valid
# for your use.
# to explicitly specify with Literal[Target.XXX] or Literal[Target.XXX, Target.YYY]
# what targets are valid for your use.
class Target(Enum):
# top level namespace (not including at)
DEFINITION = auto()