Skip to content

Commit d288f44

Browse files
intgrambv
authored andcommitted
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: python/mypy#4541
1 parent 8d46ada commit d288f44

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

stdlib/3/builtins.pyi

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,18 @@ class SystemExit(BaseException):
936936
code = 0
937937
class Exception(BaseException): ...
938938
class ArithmeticError(Exception): ...
939-
class EnvironmentError(Exception):
939+
class OSError(Exception):
940940
errno = 0
941941
strerror = ... # type: str
942-
# TODO can this be bytes?
943-
filename = ... # type: str
942+
# filename, filename2 are actually Union[str, bytes, None]
943+
filename = ... # type: Any
944+
if sys.version_info >= (3, 4):
945+
filename2 = ... # type: Any
946+
if sys.platform == 'win32':
947+
winerror = 0
948+
IOError = OSError
949+
EnvironmentError = OSError
950+
WindowsError = OSError
944951
class LookupError(Exception): ...
945952
class RuntimeError(Exception): ...
946953
class ValueError(Exception): ...
@@ -949,7 +956,6 @@ class AttributeError(Exception): ...
949956
class BufferError(Exception): ...
950957
class EOFError(Exception): ...
951958
class FloatingPointError(ArithmeticError): ...
952-
class IOError(EnvironmentError): ...
953959
class ImportError(Exception):
954960
if sys.version_info >= (3, 3):
955961
name = ... # type: str
@@ -961,7 +967,6 @@ class KeyError(LookupError): ...
961967
class MemoryError(Exception): ...
962968
class NameError(Exception): ...
963969
class NotImplementedError(RuntimeError): ...
964-
class OSError(EnvironmentError): ...
965970
class BlockingIOError(OSError):
966971
characters_written = 0
967972
class ChildProcessError(OSError): ...
@@ -978,8 +983,6 @@ class NotADirectoryError(OSError): ...
978983
class PermissionError(OSError): ...
979984
class ProcessLookupError(OSError): ...
980985
class TimeoutError(OSError): ...
981-
class WindowsError(OSError):
982-
winerror = ... # type: int
983986
class OverflowError(ArithmeticError): ...
984987
class ReferenceError(Exception): ...
985988
class StopIteration(Exception):

0 commit comments

Comments
 (0)