From 6c6f5f19da45a0ceda343209dbbc10d6879cbdbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rousset?= Date: Fri, 29 Jul 2016 14:59:26 +0200 Subject: [PATCH] apply conditionals (#417) --- stdlib/2and3/logging/__init__.pyi | 45 ++++++------- stdlib/2and3/logging/config.pyi | 13 ++-- stdlib/2and3/logging/handlers.pyi | 10 ++- stdlib/3/http/client.pyi | 107 ++++++++++++------------------ stdlib/3/http/cookiejar.pyi | 10 ++- 5 files changed, 76 insertions(+), 109 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index 7f4e5ccba..1042a74ab 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -241,15 +241,13 @@ class LoggerAdapter: def hasHandlers(self) -> bool: ... -# TODO uncomment when mypy handle conditionals -#if sys.version_info >= (3,): -# def getLogger(name: Optional[str] = ...) -> Logger: ... -#else: -# @overload -# def getLogger() -> Logger: ... -# @overload -# def getLogger(name: str) -> Logger: ... -def getLogger(name: Optional[str] = ...) -> Logger: ... +if sys.version_info >= (3,): + def getLogger(name: Optional[str] = ...) -> Logger: ... +else: + @overload + def getLogger() -> Logger: ... + @overload + def getLogger(name: str) -> Logger: ... def getLoggerClass() -> type: ... if sys.version_info >= (3,): def getLogRecordFactory() -> Callable[..., LogRecord]: ... @@ -303,23 +301,18 @@ def getLevelName(lvl: int) -> str: ... def makeLogRecord(attrdict: Mapping[str, Any]) -> LogRecord: ... -# TODO uncomment when mypy handle conditionals -#if sys.version_info >= (3,): -# def basicConfig(*, filename: str = ..., filemode: str = ..., -# format: str = ..., datefmt: str = ..., style: str = ..., -# level: int = ..., stream: IO[str] = ..., -# handlers: Iterable[Handler]) -> None: ... -#else: -# @overload -# def basicConfig() -> None: ... -# @overload -# def basicConfig(*, filename: str = ..., filemode: str = ..., -# format: str = ..., datefmt: str = ..., -# level: int = ..., stream: IO[str] = ...) -> None: ... -def basicConfig(*, filename: str = ..., filemode: str = ..., - format: str = ..., datefmt: str = ..., style: str = ..., - level: int = ..., stream: IO[str] = ..., - handlers: Iterable[Handler]) -> None: ... +if sys.version_info >= (3,): + def basicConfig(*, filename: str = ..., filemode: str = ..., + format: str = ..., datefmt: str = ..., style: str = ..., + level: int = ..., stream: IO[str] = ..., + handlers: Iterable[Handler]) -> None: ... +else: + @overload + def basicConfig() -> None: ... + @overload + def basicConfig(*, filename: str = ..., filemode: str = ..., + format: str = ..., datefmt: str = ..., + level: int = ..., stream: IO[str] = ...) -> None: ... def shutdown() -> None: ... def setLoggerClass(klass: type) -> None: ... diff --git a/stdlib/2and3/logging/config.pyi b/stdlib/2and3/logging/config.pyi index 3a76c2872..d4665d779 100644 --- a/stdlib/2and3/logging/config.pyi +++ b/stdlib/2and3/logging/config.pyi @@ -2,13 +2,12 @@ from typing import Any, Callable, Dict, Optional, IO, Union import sys -# TODO uncomment when mypy handle conditionals -#if sys.version_info >= (3,): -# from configparser import RawConfigParser -#else: -# from ConfigParser import RawConfigParser -# TODO add RawConfigParser to configparser stubs -RawConfigParser = Any +if sys.version_info >= (3,): + #from configparser import RawConfigParser + # TODO add RawConfigParser to configparser stubs + RawConfigParser = Any +else: + from ConfigParser import RawConfigParser def dictConfig(config: Dict[str, Any]) -> None: ... diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index 85ee34259..7aedcb2d8 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -3,12 +3,10 @@ from typing import Any, Callable, Optional, Tuple, Union, overload from logging import Handler, FileHandler, LogRecord import datetime -# TODO uncomment when mypy handle conditionals -#if sys.version_info >= (3,): -# from queue import Queue -#else: -# from Queue import Queue -Queue = Any +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue from socket import SocketType # TODO update socket stubs to add SocketKind SocketKind = int diff --git a/stdlib/3/http/client.pyi b/stdlib/3/http/client.pyi index 6c0e51136..f11ab9970 100644 --- a/stdlib/3/http/client.pyi +++ b/stdlib/3/http/client.pyi @@ -79,70 +79,49 @@ responses = ... # type: Dict[int, str] class HTTPMessage(email.message.Message): ... -# TODO uncomment when mypy handle conditionals -#if sys.version_info >= (3, 5): -# class HTTPResponse(io.BufferedIOBase): -# msg = ... # type: HTTPMessage -# version = ... # type: int -# debuglevel = ... # type: int -# closed = ... # type: bool -# status = ... # type: int -# reason = ... # type: str -# def read(self, amt: Optional[int] = ...) -> bytes: ... -# def readinto(self, b: bytearray) -> int: ... -# @overload -# def getheader(self, name: str) -> Optional[str]: ... -# @overload -# def getheader(self, name: str, default: _T) -> Union[str, _T]: ... -# def getheaders(self) -> List[Tuple[str, str]]: ... -# def fileno(self) -> int: ... -# def __iter__(self) -> Iterator[bytes]: ... -# def __enter__(self) -> 'HTTPResponse': ... -# def __exit__(self, exc_type: Optional[type], -# exc_val: Optional[Exception], -# exc_tb: Optional[types.TracebackType]) -> bool: ... -#else: -# class HTTPResponse: -# msg = ... # type: HTTPMessage -# version = ... # type: int -# debuglevel = ... # type: int -# closed = ... # type: bool -# status = ... # type: int -# reason = ... # type: str -# def read(self, amt: Optional[int] = ...) -> bytes: ... -# if sys.version_info >= (3, 3): -# def readinto(self, b: bytearray) -> int: ... -# @overload -# def getheader(self, name: str) -> Optional[str]: ... -# @overload -# def getheader(self, name: str, default: _T) -> Union[str, _T]: ... -# def getheaders(self) -> List[Tuple[str, str]]: ... -# def fileno(self) -> int: ... -# def __iter__(self) -> Iterator[bytes]: ... -# def __enter__(self) -> 'HTTPResponse': ... -# def __exit__(self, exc_type: Optional[type], -# exc_val: Optional[Exception], -# exc_tb: Optional[types.TracebackType]) -> bool: ... -class HTTPResponse(io.BufferedIOBase): - msg = ... # type: HTTPMessage - version = ... # type: int - debuglevel = ... # type: int - closed = ... # type: bool - status = ... # type: int - reason = ... # type: str - def read(self, amt: Optional[int] = ...) -> bytes: ... - def readinto(self, b: bytearray) -> int: ... - @overload - def getheader(self, name: str) -> Optional[str]: ... - @overload - def getheader(self, name: str, default: _T) -> Union[str, _T]: ... - def getheaders(self) -> List[Tuple[str, str]]: ... - def fileno(self) -> int: ... - def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self) -> 'HTTPResponse': ... - def __exit__(self, exc_type: Optional[type], - exc_val: Optional[Exception], - exc_tb: Optional[types.TracebackType]) -> bool: ... +if sys.version_info >= (3, 5): + class HTTPResponse(io.BufferedIOBase): + msg = ... # type: HTTPMessage + version = ... # type: int + debuglevel = ... # type: int + closed = ... # type: bool + status = ... # type: int + reason = ... # type: str + def read(self, amt: Optional[int] = ...) -> bytes: ... + def readinto(self, b: bytearray) -> int: ... + @overload + def getheader(self, name: str) -> Optional[str]: ... + @overload + def getheader(self, name: str, default: _T) -> Union[str, _T]: ... + def getheaders(self) -> List[Tuple[str, str]]: ... + def fileno(self) -> int: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> 'HTTPResponse': ... + def __exit__(self, exc_type: Optional[type], + exc_val: Optional[Exception], + exc_tb: Optional[types.TracebackType]) -> bool: ... +else: + class HTTPResponse: + msg = ... # type: HTTPMessage + version = ... # type: int + debuglevel = ... # type: int + closed = ... # type: bool + status = ... # type: int + reason = ... # type: str + def read(self, amt: Optional[int] = ...) -> bytes: ... + if sys.version_info >= (3, 3): + def readinto(self, b: bytearray) -> int: ... + @overload + def getheader(self, name: str) -> Optional[str]: ... + @overload + def getheader(self, name: str, default: _T) -> Union[str, _T]: ... + def getheaders(self) -> List[Tuple[str, str]]: ... + def fileno(self) -> int: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> 'HTTPResponse': ... + def __exit__(self, exc_type: Optional[type], + exc_val: Optional[Exception], + exc_tb: Optional[types.TracebackType]) -> bool: ... class HTTPConnection: if sys.version_info >= (3, 4): diff --git a/stdlib/3/http/cookiejar.pyi b/stdlib/3/http/cookiejar.pyi index 3761e089b..38de5a33c 100644 --- a/stdlib/3/http/cookiejar.pyi +++ b/stdlib/3/http/cookiejar.pyi @@ -7,12 +7,10 @@ from urllib.request import Request _T = TypeVar('_T') -# TODO uncomment when mypy handles conditionals -#if sys.version_info >= (3, 3): -# class LoadError(OSError): ... -#else: -# class LoadError(IOError): ... -class LoadError(OSError): ... +if sys.version_info >= (3, 3): + class LoadError(OSError): ... +else: + class LoadError(IOError): ... class CookieJar(Iterable['Cookie']):