From d215f502c6de8670f360b090923391054112ff86 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 3 Dec 2019 05:33:37 -0800 Subject: [PATCH] Improve warnings stubs (#3501) * merge 2and3 for _warnings * move warn and warn_explicit into _warnings --- stdlib/2/_warnings.pyi | 16 ------------- stdlib/2and3/_warnings.pyi | 34 ++++++++++++++++++++++++++ stdlib/2and3/warnings.pyi | 49 +++++++++++--------------------------- stdlib/3/_warnings.pyi | 11 --------- 4 files changed, 48 insertions(+), 62 deletions(-) delete mode 100644 stdlib/2/_warnings.pyi create mode 100644 stdlib/2and3/_warnings.pyi delete mode 100644 stdlib/3/_warnings.pyi diff --git a/stdlib/2/_warnings.pyi b/stdlib/2/_warnings.pyi deleted file mode 100644 index 192fbd213..000000000 --- a/stdlib/2/_warnings.pyi +++ /dev/null @@ -1,16 +0,0 @@ -from typing import Any, Dict, List, Optional, Tuple, Type - -default_action: str -filters: List[Tuple[Any, ...]] -once_registry: Dict[Any, Any] - -def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... -def warn_explicit( - message: Warning, - category: Optional[Type[Warning]], - filename: str, - lineno: int, - module: Any = ..., - registry: Dict[Any, Any] = ..., - module_globals: Dict[Any, Any] = ..., -) -> None: ... diff --git a/stdlib/2and3/_warnings.pyi b/stdlib/2and3/_warnings.pyi new file mode 100644 index 000000000..f764f7c77 --- /dev/null +++ b/stdlib/2and3/_warnings.pyi @@ -0,0 +1,34 @@ +import sys +from typing import Any, Dict, List, Optional, Tuple, Type, Union, overload + +if sys.version_info >= (3, 0): + _defaultaction: str + _onceregistry: Dict[Any, Any] +else: + default_action: str + once_registry: Dict[Any, Any] +filters: List[Tuple[Any, ...]] +@overload +def warn(message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... +@overload +def warn(message: Warning, category: Any = ..., stacklevel: int = ...) -> None: ... +@overload +def warn_explicit( + message: str, + category: Type[Warning], + filename: str, + lineno: int, + module: Optional[str] = ..., + registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., + module_globals: Optional[Dict[str, Any]] = ..., +) -> None: ... +@overload +def warn_explicit( + message: Warning, + category: Any, + filename: str, + lineno: int, + module: Optional[str] = ..., + registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., + module_globals: Optional[Dict[str, Any]] = ..., +) -> None: ... diff --git a/stdlib/2and3/warnings.pyi b/stdlib/2and3/warnings.pyi index 6e2c3a53f..71be4895d 100644 --- a/stdlib/2and3/warnings.pyi +++ b/stdlib/2and3/warnings.pyi @@ -1,38 +1,17 @@ -# Stubs for warnings - -import sys -from typing import Any, Dict, List, NamedTuple, Optional, overload, TextIO, Tuple, Type, Union +from typing import List, NamedTuple, Optional, overload, TextIO, Type from types import ModuleType, TracebackType +from typing_extensions import Literal -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from _warnings import warn as warn, warn_explicit as warn_explicit -@overload -def warn(message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... -@overload -def warn(message: Warning, category: Any = ..., stacklevel: int = ...) -> None: ... -@overload -def warn_explicit(message: str, category: Type[Warning], - filename: str, lineno: int, module: Optional[str] = ..., - registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., - module_globals: Optional[Dict[str, Any]] = ...) -> None: ... -@overload -def warn_explicit(message: Warning, category: Any, - filename: str, lineno: int, module: Optional[str] = ..., - registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., - module_globals: Optional[Dict[str, Any]] = ...) -> None: ... -def showwarning(message: str, category: Type[Warning], filename: str, - lineno: int, file: Optional[TextIO] = ..., - line: Optional[str] = ...) -> None: ... -def formatwarning(message: str, category: Type[Warning], filename: str, - lineno: int, line: Optional[str] = ...) -> str: ... -def filterwarnings(action: str, message: str = ..., - category: Type[Warning] = ..., module: str = ..., - lineno: int = ..., append: bool = ...) -> None: ... -def simplefilter(action: str, category: Type[Warning] = ..., lineno: int = ..., - append: bool = ...) -> None: ... +def showwarning( + message: str, category: Type[Warning], filename: str, lineno: int, file: Optional[TextIO] = ..., line: Optional[str] = ... +) -> None: ... +def formatwarning(message: str, category: Type[Warning], filename: str, lineno: int, line: Optional[str] = ...) -> str: ... +def filterwarnings( + action: str, message: str = ..., category: Type[Warning] = ..., module: str = ..., lineno: int = ..., append: bool = ... +) -> None: ... +def simplefilter(action: str, category: Type[Warning] = ..., lineno: int = ..., append: bool = ...) -> None: ... def resetwarnings() -> None: ... class _Record(NamedTuple): @@ -51,9 +30,9 @@ class catch_warnings: @overload def __new__(cls, *, record: bool, module: Optional[ModuleType] = ...) -> catch_warnings: ... def __enter__(self) -> Optional[List[_Record]]: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType]) -> None: ... + def __exit__( + self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] + ) -> None: ... class _catch_warnings_without_records(catch_warnings): def __enter__(self) -> None: ... diff --git a/stdlib/3/_warnings.pyi b/stdlib/3/_warnings.pyi deleted file mode 100644 index c055b2a1d..000000000 --- a/stdlib/3/_warnings.pyi +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Any, Dict, List, Optional, Tuple, Type - -_defaultaction: str -_onceregistry: Dict[Any, Any] -filters: List[Tuple[Any, ...]] - -def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... -def warn_explicit(message: Warning, category: Optional[Type[Warning]], - filename: str, lineno: int, - module: Any = ..., registry: Dict[Any, Any] = ..., - module_globals: Dict[Any, Any] = ...) -> None: ...