Use Literal in a few more places (#3176)

This commit is contained in:
Sebastian Rittau
2019-08-10 22:08:18 +02:00
committed by Jelle Zijlstra
parent c579f91077
commit 628eee29f7
6 changed files with 54 additions and 17 deletions

View File

@@ -1,5 +1,11 @@
import sys
from typing import Any, Union, Tuple, Optional, overload, Dict, NoReturn, Sequence
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
CREATE_NEW_CONSOLE: int
CREATE_NEW_PROCESS_GROUP: int
DUPLICATE_CLOSE_SOURCE: int
@@ -46,11 +52,12 @@ WAIT_TIMEOUT: int
def CloseHandle(handle: int) -> None: ...
# TODO: once literal types are supported, overload with Literal[True/False]
@overload
def ConnectNamedPipe(handle: int, overlapped: Union[int, bool]) -> Any: ...
def ConnectNamedPipe(handle: int, overlapped: Literal[True]) -> Overlapped: ...
@overload
def ConnectNamedPipe(handle: int) -> None: ...
def ConnectNamedPipe(handle: int, overlapped: Literal[False] = ...) -> None: ...
@overload
def ConnectNamedPipe(handle: int, overlapped: bool) -> Any: ...
def CreateFile(file_name: str, desired_access: int, share_mode: int, security_attributes: int, creation_disposition: int, flags_and_attributes: int, template_file: int) -> int: ...
def CreateJunction(src_path: str, dest_path: str) -> None: ...

View File

@@ -1,12 +1,9 @@
# Python 3.5 ast
import sys
# Rename typing to _typing, as not to conflict with typing imported
# from _ast below when loaded in an unorthodox way by the Dropbox
# internal Bazel integration.
import typing as _typing
from typing import overload, Any, Iterator, Optional, Union, TypeVar
from typing_extensions import Literal
# The same unorthodox Bazel integration causes issues with sys, which
# is imported in both modules. unfortunately we can't just rename sys,
@@ -14,6 +11,11 @@ from typing_extensions import Literal
# sys.
from _ast import * # type: ignore
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
class NodeVisitor():
def visit(self, node: AST) -> Any: ...
def generic_visit(self, node: AST) -> Any: ...

View File

@@ -1,7 +1,10 @@
# Stubs for gettext (Python 3.4)
import sys
from typing import overload, Any, Container, IO, Iterable, Optional, Type, TypeVar
from typing_extensions import Literal
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
class NullTranslations:
def __init__(self, fp: IO[str] = ...) -> None: ...

View File

@@ -7,9 +7,13 @@ from typing import (
Generic, TypeVar, AnyStr,
overload,
)
from typing_extensions import Literal
from types import TracebackType
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
# We prefer to annotate inputs to methods (eg subprocess.check_call) with these
# union types.
# For outputs we use laborious literal based overloads to try to determine