Skip to content
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

bpo-37467: Fix PyErr_Display() for bytes filename #14504

Merged
merged 3 commits into from Jul 1, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jul 1, 2019

Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

https://bugs.python.org/issue37467

Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.
@vstinner
Copy link
Member Author

vstinner commented Jul 1, 2019

The test fails on the CI, but it pass locally on my Linux laptop and in my Windows VM. I don't understand why.

Example of failure on AppVeyor:

FAIL: test_excepthook_bytes_filename (test.test_sys.SysModuleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\cpython\lib\test\test_sys.py", line 91, in test_excepthook_bytes_filename
    self.assertIn("""  File "b'bytes_filename'", line 123\n""", err)
AssertionError: '  File "b\'bytes_filename\'", line 123\n' not found in 'Traceback (most recent call last):\n  File "C:\\projects\\cpython\\lib\\test\\test_sys.py", line 85, in test_excepthook_bytes_filename\n    raise SyntaxError("msg", (b"bytes_filename", 123, 0, "text"))\n\n'

vstinner added 2 commits Jul 1, 2019
* Sort imports
* Rename numruns global var to INTERN_NUMRUNS
* Add DisplayHookTest and ExceptHookTest test case classes
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method
* Test error case (call hook with no argument) after the success case
@vstinner vstinner merged commit f9b7457 into python:master Jul 1, 2019
@miss-islington
Copy link
Contributor

miss-islington commented Jul 1, 2019

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒🤖 I'm not a witch! I'm not a witch!

@vstinner vstinner deleted the err_display_bytes branch Jul 1, 2019
@bedevere-bot
Copy link

bedevere-bot commented Jul 1, 2019

GH-14514 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 1, 2019
Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

Cleanup also test_sys:

* Sort imports.
* Rename numruns global var to INTERN_NUMRUNS.
* Add DisplayHookTest and ExceptHookTest test case classes.
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method.
* Test error case (call hook with no argument) after the success case.
(cherry picked from commit f9b7457)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
@miss-islington
Copy link
Contributor

miss-islington commented Jul 1, 2019

Sorry, @vstinner, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker f9b7457bd7f438263e0d2dd1f70589ad56a2585e 3.7

@bedevere-bot
Copy link

bedevere-bot commented Jul 1, 2019

GH-14515 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Jul 1, 2019
Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

Cleanup also test_sys:

* Sort imports.
* Rename numruns global var to INTERN_NUMRUNS.
* Add DisplayHookTest and ExceptHookTest test case classes.
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method.
* Test error case (call hook with no argument) after the success case.
(cherry picked from commit f9b7457)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
vstinner added a commit that referenced this pull request Jul 1, 2019
Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

Cleanup also test_sys:

* Sort imports.
* Rename numruns global var to INTERN_NUMRUNS.
* Add DisplayHookTest and ExceptHookTest test case classes.
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method.
* Test error case (call hook with no argument) after the success case.

(cherry picked from commit f9b7457)
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

Cleanup also test_sys:

* Sort imports.
* Rename numruns global var to INTERN_NUMRUNS.
* Add DisplayHookTest and ExceptHookTest test case classes.
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method.
* Test error case (call hook with no argument) after the success case.
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
Fix sys.excepthook() and PyErr_Display() if a filename is a bytes
string. For example, for a SyntaxError exception where the filename
attribute is a bytes string.

Cleanup also test_sys:

* Sort imports.
* Rename numruns global var to INTERN_NUMRUNS.
* Add DisplayHookTest and ExceptHookTest test case classes.
* Don't save/restore sys.stdout and sys.displayhook using
  setUp()/tearDown(): do it in each test method.
* Test error case (call hook with no argument) after the success case.
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.

None yet

4 participants