Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2606a6f

Browse files
committed
Issue #16719: Get rid of WindowsError. Use OSError instead
Patch by Serhiy Storchaka.
1 parent 8a045cb commit 2606a6f

28 files changed

Lines changed: 79 additions & 87 deletions

Doc/library/shutil.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,10 @@ provided by this module. ::
393393
errors.extend(err.args[0])
394394
try:
395395
copystat(src, dst)
396-
except WindowsError:
397-
# can't copy file access times on Windows
398-
pass
399396
except OSError as why:
400-
errors.extend((src, dst, str(why)))
397+
# can't copy file access times on Windows
398+
if why.winerror is None:
399+
errors.extend((src, dst, str(why)))
401400
if errors:
402401
raise Error(errors)
403402

Lib/ctypes/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class HRESULT(_SimpleCData):
395395
_type_ = "l"
396396
# _check_retval_ is called with the function's result when it
397397
# is used as restype. It checks for the FAILED bit, and
398-
# raises a WindowsError if it is set.
398+
# raises an OSError if it is set.
399399
#
400400
# The _check_retval_ method is implemented in C, so that the
401401
# method definition itself is not included in the traceback
@@ -407,7 +407,7 @@ class HRESULT(_SimpleCData):
407407
class OleDLL(CDLL):
408408
"""This class represents a dll exporting functions using the
409409
Windows stdcall calling convention, and returning HRESULT.
410-
HRESULT error values are automatically raised as WindowsError
410+
HRESULT error values are automatically raised as OSError
411411
exceptions.
412412
"""
413413
_func_flags_ = _FUNCFLAG_STDCALL
@@ -456,7 +456,7 @@ def WinError(code=None, descr=None):
456456
code = GetLastError()
457457
if descr is None:
458458
descr = FormatError(code).strip()
459-
return WindowsError(None, descr, None, code)
459+
return OSError(None, descr, None, code)
460460

461461
if sizeof(c_uint) == sizeof(c_void_p):
462462
c_size_t = c_uint

Lib/ctypes/test/test_checkretval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_checkretval(self):
3131
pass
3232
else:
3333
def test_oledll(self):
34-
self.assertRaises(WindowsError,
34+
self.assertRaises(OSError,
3535
oledll.oleaut32.CreateTypeLib2,
3636
0, None, None)
3737

Lib/ctypes/test/test_win32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_SEH(self):
4040
# Call functions with invalid arguments, and make sure
4141
# that access violations are trapped and raise an
4242
# exception.
43-
self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32)
43+
self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
4444

4545
def test_noargs(self):
4646
# This is a special case on win32 x64

Lib/idlelib/EditorWindow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def python_docs(self, event=None):
536536
if sys.platform[:3] == 'win':
537537
try:
538538
os.startfile(self.help_url)
539-
except WindowsError as why:
539+
except OSError as why:
540540
tkMessageBox.showerror(title='Document Start Failure',
541541
message=str(why), parent=self.text)
542542
else:
@@ -845,7 +845,7 @@ def display_extra_help(helpfile=helpfile):
845845
if sys.platform[:3] == 'win':
846846
try:
847847
os.startfile(helpfile)
848-
except WindowsError as why:
848+
except OSError as why:
849849
tkMessageBox.showerror(title='Document Start Failure',
850850
message=str(why), parent=self.text)
851851
else:

Lib/importlib/_bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ class WindowsRegistryFinder:
755755
def _open_registry(cls, key):
756756
try:
757757
return _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key)
758-
except WindowsError:
758+
except OSError:
759759
return _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key)
760760

761761
@classmethod
@@ -769,7 +769,7 @@ def _search_registry(cls, fullname):
769769
try:
770770
with cls._open_registry(key) as hkey:
771771
filepath = _winreg.QueryValue(hkey, "")
772-
except WindowsError:
772+
except OSError:
773773
return None
774774
return filepath
775775

Lib/multiprocessing/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def PipeClient(address):
676676
0, _winapi.NULL, _winapi.OPEN_EXISTING,
677677
_winapi.FILE_FLAG_OVERLAPPED, _winapi.NULL
678678
)
679-
except WindowsError as e:
679+
except OSError as e:
680680
if e.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
681681
_winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
682682
raise

Lib/ntpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def lexists(path):
331331
"""Test whether a path exists. Returns True for broken symbolic links"""
332332
try:
333333
st = os.lstat(path)
334-
except (OSError, WindowsError):
334+
except OSError:
335335
return False
336336
return True
337337

@@ -584,7 +584,7 @@ def abspath(path):
584584
if path: # Empty path must return current working directory.
585585
try:
586586
path = _getfullpathname(path)
587-
except WindowsError:
587+
except OSError:
588588
pass # Bad path - return unchanged.
589589
elif isinstance(path, bytes):
590590
path = os.getcwdb()

Lib/platform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
581581
# Discard any type that isn't REG_SZ
582582
if type == REG_SZ and name.find("Server") != -1:
583583
product_type = VER_NT_SERVER
584-
except WindowsError:
584+
except OSError:
585585
# Use default of VER_NT_WORKSTATION
586586
pass
587587

Lib/shutil.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class RegistryError(Exception):
6060
and unpacking registeries fails"""
6161

6262

63-
try:
64-
WindowsError
65-
except NameError:
66-
WindowsError = None
67-
6863
def copyfileobj(fsrc, fdst, length=16*1024):
6964
"""copy data from file-like object fsrc to file-like object fdst"""
7065
while 1:
@@ -334,10 +329,8 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
334329
try:
335330
copystat(src, dst)
336331
except OSError as why:
337-
if WindowsError is not None and isinstance(why, WindowsError):
338-
# Copying file access times may fail on Windows
339-
pass
340-
else:
332+
# Copying file access times may fail on Windows
333+
if why.winerror is None:
341334
errors.append((src, dst, str(why)))
342335
if errors:
343336
raise Error(errors)

0 commit comments

Comments
 (0)