Use TypeAlias where possible for type aliases (#7630)

This commit is contained in:
Alex Waygood
2022-04-16 02:01:00 +01:00
committed by GitHub
parent c0e6dd3f3f
commit 740193a8fc
218 changed files with 760 additions and 625 deletions

View File

@@ -13,9 +13,9 @@ from abc import ABCMeta, abstractmethod
from importlib.machinery import ModuleSpec
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, overload, runtime_checkable
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias
_Path = bytes | str
_Path: TypeAlias = bytes | str
class Finder(metaclass=ABCMeta): ...

View File

@@ -4,6 +4,7 @@ from contextlib import AbstractContextManager
from pathlib import Path
from types import ModuleType
from typing import Any, BinaryIO, Iterator, TextIO
from typing_extensions import TypeAlias
if sys.version_info >= (3, 10):
__all__ = [
@@ -37,8 +38,8 @@ elif sys.version_info >= (3, 9):
else:
__all__ = ["Package", "Resource", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"]
Package = str | ModuleType
Resource = str | os.PathLike[Any]
Package: TypeAlias = str | ModuleType
Resource: TypeAlias = str | os.PathLike[Any]
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ...