Skip to content

bpo-47099: Replace with_traceback() with exception chaining and reraising #32074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

arhadthedev
Copy link
Member

@arhadthedev arhadthedev commented Mar 23, 2022

This PR changes exception chaining used in the library from Exception.with_traceback/sys.exc_info to PEP 3134.

There are minor user-visible changes in the exception report:

  • the line During handling of the above exception, another exception occurred is replaced with The above exception was the direct cause of the following exception

    Comparison of the full console output Before:
    Python 3.11.0a6 (main, Mar  7 2022, 16:46:19) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib.parse
    >>> urllib.parse.urlencode(None)
    Traceback (most recent call last):
      File "C:\Program Files\Python311\Lib\urllib\parse.py", line 937, in urlencode
        if len(query) and not isinstance(query[0], tuple):
           ^^^^^^^^^^
    TypeError: object of type 'NoneType' has no len()
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python311\Lib\urllib\parse.py", line 945, in urlencode
        raise TypeError("not a valid non-string sequence "
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python311\Lib\urllib\parse.py", line 937, in urlencode
        if len(query) and not isinstance(query[0], tuple):
           ^^^^^^^^^^
    TypeError: not a valid non-string sequence or mapping object
    

    After:

    Python 3.11.0a6+ (main, Mar 23 2022, 12:00:42) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib.parse
    >>> urllib.parse.urlencode(None)
    Traceback (most recent call last):
      File "C:\Users\oleg\Documents\dev\cpython\Lib\urllib\parse.py", line 937, in urlencode
        if len(query) and not isinstance(query[0], tuple):
           ^^^^^^^^^^
    TypeError: object of type 'NoneType' has no len()
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\oleg\Documents\dev\cpython\Lib\urllib\parse.py", line 944, in urlencode
        raise TypeError("not a valid non-string sequence "
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: not a valid non-string sequence or mapping object
    
  • all URLError exception messages raised in urllib.request.URLopener now contain a colon between ftp error and the rest of the message. Previously, URLopener.open_ftp() missed the colon.

https://bugs.python.org/issue47099

@arhadthedev
Copy link
Member Author

@asvetlov Thank you for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants