-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Use io.open in notebookapp.py to fix #4303 #4348
Conversation
Following the discussion at #4340, in Python 2 we need `io.open` rather than `open` if using a file descriptor rather than a file name.
notebook/notebookapp.py
Outdated
@@ -1671,7 +1671,7 @@ def server_info(self): | |||
def write_server_info_file(self): | |||
"""Write the result of server_info() to the JSON file info_file.""" | |||
try: | |||
with open(self.info_file, 'w') as f: | |||
with io.open(self.info_file, 'w') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add encoding='utf-8'
here? It's not the same problem, but it would be good to do it while we're looking at this code.
The test failures are because of tornado 6.0a1. I've committed to 5.7.x to limit it to tornado 5.x; I'll close and reopen this pull request to test it again. |
@@ -1671,7 +1671,7 @@ def server_info(self): | |||
def write_server_info_file(self): | |||
"""Write the result of server_info() to the JSON file info_file.""" | |||
try: | |||
with open(self.info_file, 'w') as f: | |||
with io.open(self.info_file, 'w', encoding='utf-8') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think I told you to change the wrong one. This one needs to stay as regular open()
, because the JSON module on Python 2 produces bytes, not unicode.
I thought we were looking at this line, but it already uses io.open()
:
notebook/notebook/notebookapp.py
Line 1699 in 0579bc0
with io.open(self.browser_open_file, 'w', encoding='utf-8') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If commit f8d7d40 has all that is needed, can you use only that commit
and leave out the further two commits in this branch when you merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I'll open a new PR so it re-runs the CI tests with just that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #4349
Grepping for
|
Merged #4349 |
Following the discussion at #4340, in Python 2 we need
io.open
rather than
open
if using a file descriptor rather than a file name.