diff options
author | Oleg Iarygin <oleg@arhadthedev.net> | 2022-03-30 12:28:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 12:28:20 (GMT) |
commit | a03a09e068435f47d02649dda93988dc44ffaaf1 (patch) | |
tree | 864a523218399cc068ec68567359e616740bac9b /Lib/urllib | |
parent | f08a191882f75bb79d42a49039892105b2212fb9 (diff) | |
download | cpython-a03a09e068435f47d02649dda93988dc44ffaaf1.zip cpython-a03a09e068435f47d02649dda93988dc44ffaaf1.tar.gz cpython-a03a09e068435f47d02649dda93988dc44ffaaf1.tar.bz2 |
Replace with_traceback() with exception chaining and reraising (GH-32074)
Diffstat (limited to 'Lib/urllib')
-rw-r--r-- | Lib/urllib/parse.py | 5 | ||||
-rw-r--r-- | Lib/urllib/request.py | 10 |
2 files changed, 6 insertions, 9 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 67ba308..d70a694 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -940,10 +940,9 @@ def urlencode(query, doseq=False, safe='', encoding=None, errors=None, # but that's a minor nit. Since the original implementation # allowed empty dicts that type of behavior probably should be # preserved for consistency - except TypeError: - ty, va, tb = sys.exc_info() + except TypeError as err: raise TypeError("not a valid non-string sequence " - "or mapping object").with_traceback(tb) + "or mapping object") from err l = [] if not doseq: diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 02f9626..84997f2 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1579,8 +1579,7 @@ class FTPHandler(BaseHandler): headers = email.message_from_string(headers) return addinfourl(fp, headers, req.full_url) except ftplib.all_errors as exp: - exc = URLError('ftp error: %r' % exp) - raise exc.with_traceback(sys.exc_info()[2]) + raise URLError(f'ftp error: {exp}') from exp def connect_ftp(self, user, passwd, host, port, dirs, timeout): return ftpwrapper(user, passwd, host, port, dirs, timeout, @@ -1791,7 +1790,7 @@ class URLopener: except (HTTPError, URLError): raise except OSError as msg: - raise OSError('socket error', msg).with_traceback(sys.exc_info()[2]) + raise OSError('socket error', msg) from msg def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" @@ -2093,7 +2092,7 @@ class URLopener: headers = email.message_from_string(headers) return addinfourl(fp, headers, "ftp:" + url) except ftperrors() as exp: - raise URLError('ftp error %r' % exp).with_traceback(sys.exc_info()[2]) + raise URLError(f'ftp error: {exp}') from exp def open_data(self, url, data=None): """Use "data" URL.""" @@ -2443,8 +2442,7 @@ class ftpwrapper: conn, retrlen = self.ftp.ntransfercmd(cmd) except ftplib.error_perm as reason: if str(reason)[:3] != '550': - raise URLError('ftp error: %r' % reason).with_traceback( - sys.exc_info()[2]) + raise URLError(f'ftp error: {reason}') from reason if not conn: # Set transfer mode to ASCII! self.ftp.voidcmd('TYPE A') |