From 984307bf456736fc831c6556d5b3bc3ad86c3ae5 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 12 Mar 2017 20:48:48 -0700 Subject: [PATCH] fix odd version comparisons (#988) "> (3,)" works but looks like the code is checking for Python 4. "<= (3, 5)" was intended to check for versions up to and including 3.5, and probably works that way in current type checkers. However, sys.version_info is actually a 5-tuple that is greater than (3, 5), so a hypothetical type checker that uses the full version info would interpret this check incorrectly. This ensures that all version_info comparisons use <, >=, ==, or !=. --- stdlib/2and3/logging/__init__.pyi | 6 +++--- stdlib/2and3/logging/handlers.pyi | 2 +- stdlib/3.4/pathlib.pyi | 4 ++-- stdlib/3/base64.pyi | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/2and3/logging/__init__.pyi b/stdlib/2and3/logging/__init__.pyi index 286c8590f..6eb6863bd 100644 --- a/stdlib/2and3/logging/__init__.pyi +++ b/stdlib/2and3/logging/__init__.pyi @@ -31,7 +31,7 @@ class Logger: def isEnabledFor(self, lvl: int) -> bool: ... def getEffectiveLevel(self) -> int: ... def getChild(self, suffix: str) -> 'Logger': ... - if sys.version_info > (3,): + if sys.version_info >= (3,): def debug(self, msg: Text, *args: Any, exc_info: _ExcInfoType = ..., stack_info: bool = ..., extra: Dict[str, Any] = ..., **kwargs: Any) -> None: ... @@ -218,7 +218,7 @@ class LogRecord: class LoggerAdapter: def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ... def process(self, msg: Text, kwargs: MutableMapping[str, Any]) -> Tuple[str, MutableMapping[str, Any]]: ... - if sys.version_info > (3,): + if sys.version_info >= (3,): def debug(self, msg: Text, *args: Any, exc_info: _ExcInfoType = ..., stack_info: bool = ..., extra: Dict[str, Any] = ..., **kwargs: Any) -> None: ... @@ -280,7 +280,7 @@ def getLoggerClass() -> type: ... if sys.version_info >= (3,): def getLogRecordFactory() -> Callable[..., LogRecord]: ... -if sys.version_info > (3,): +if sys.version_info >= (3,): def debug(msg: Text, *args: Any, exc_info: _ExcInfoType = ..., stack_info: bool = ..., extra: Dict[str, Any] = ..., **kwargs: Any) -> None: ... diff --git a/stdlib/2and3/logging/handlers.pyi b/stdlib/2and3/logging/handlers.pyi index 50ffa0e59..604139730 100644 --- a/stdlib/2and3/logging/handlers.pyi +++ b/stdlib/2and3/logging/handlers.pyi @@ -180,7 +180,7 @@ class HTTPHandler(Handler): def mapLogRecord(self, record: LogRecord) -> Dict[str, Any]: ... -if sys.version_info > (3,): +if sys.version_info >= (3,): class QueueHandler(Handler): def __init__(self, queue: Queue) -> None: ... def prepare(self, record: LogRecord) -> Any: ... diff --git a/stdlib/3.4/pathlib.pyi b/stdlib/3.4/pathlib.pyi index ef142a7c7..539f91593 100644 --- a/stdlib/3.4/pathlib.pyi +++ b/stdlib/3.4/pathlib.pyi @@ -67,7 +67,7 @@ class Path(PurePath): def iterdir(self) -> Generator[Path, None, None]: ... def lchmod(self, mode: int) -> None: ... def lstat(self) -> os.stat_result: ... - if sys.version_info <= (3, 4): + if sys.version_info < (3, 5): def mkdir(self, mode: int = ..., parents: bool = ...) -> None: ... else: @@ -79,7 +79,7 @@ class Path(PurePath): def owner(self) -> str: ... def rename(self, target: Union[str, PurePath]) -> None: ... def replace(self, target: Union[str, PurePath]) -> None: ... - if sys.version_info <= (3, 5): + if sys.version_info < (3, 6): def resolve(self: _P) -> _P: ... else: def resolve(self: _P, strict: bool = ...) -> _P: ... diff --git a/stdlib/3/base64.pyi b/stdlib/3/base64.pyi index 4e76ebbd9..5732c524b 100644 --- a/stdlib/3/base64.pyi +++ b/stdlib/3/base64.pyi @@ -4,7 +4,7 @@ from typing import IO, Union import sys -if sys.version_info <= (3, 2): +if sys.version_info < (3, 3): _encodable = bytes _decodable = bytes elif sys.version_info[:2] == (3, 3):