From d288f443b9349c28b03fff2e04d761ec43bf2210 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Wed, 14 Feb 2018 18:33:56 +0200 Subject: [PATCH] Merge {IO,Environment,Windows}Error into OSError for Python 3.3+ (#1852) Starting with Python 3.3, IOError, EnvironmentError and WindowsError are aliases for OSError, which has all the attributes. Reference: * https://docs.python.org/3/library/exceptions.html#OSError * https://www.python.org/dev/peps/pep-3151/ * OSError: Drop Python <3.3 compatibility * Use Any instead of Union for filename/filename2 type, per GvR comment See: https://github.com/python/mypy/pull/4541 --- stdlib/3/builtins.pyi | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index d0eafd70e..96df001f4 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -936,11 +936,18 @@ class SystemExit(BaseException): code = 0 class Exception(BaseException): ... class ArithmeticError(Exception): ... -class EnvironmentError(Exception): +class OSError(Exception): errno = 0 strerror = ... # type: str - # TODO can this be bytes? - filename = ... # type: str + # filename, filename2 are actually Union[str, bytes, None] + filename = ... # type: Any + if sys.version_info >= (3, 4): + filename2 = ... # type: Any + if sys.platform == 'win32': + winerror = 0 +IOError = OSError +EnvironmentError = OSError +WindowsError = OSError class LookupError(Exception): ... class RuntimeError(Exception): ... class ValueError(Exception): ... @@ -949,7 +956,6 @@ class AttributeError(Exception): ... class BufferError(Exception): ... class EOFError(Exception): ... class FloatingPointError(ArithmeticError): ... -class IOError(EnvironmentError): ... class ImportError(Exception): if sys.version_info >= (3, 3): name = ... # type: str @@ -961,7 +967,6 @@ class KeyError(LookupError): ... class MemoryError(Exception): ... class NameError(Exception): ... class NotImplementedError(RuntimeError): ... -class OSError(EnvironmentError): ... class BlockingIOError(OSError): characters_written = 0 class ChildProcessError(OSError): ... @@ -978,8 +983,6 @@ class NotADirectoryError(OSError): ... class PermissionError(OSError): ... class ProcessLookupError(OSError): ... class TimeoutError(OSError): ... -class WindowsError(OSError): - winerror = ... # type: int class OverflowError(ArithmeticError): ... class ReferenceError(Exception): ... class StopIteration(Exception):