Skip to content

bpo-37330: open() no longer accept 'U' in file mode - #14204

Closed
vstinner wants to merge 3 commits into
python:masterfrom
vstinner:remove_open_universal
Closed

bpo-37330: open() no longer accept 'U' in file mode#14204
vstinner wants to merge 3 commits into
python:masterfrom
vstinner:remove_open_universal

Conversation

@vstinner

@vstinnervstinner commented Jun 18, 2019

Copy link
Copy Markdown
Member

open(), io.open(), codecs.open() and fileinput.FileInput no longer
accept "U" ("universal newline") in the file mode. This flag was
deprecated since Python 3.3.

https://bugs.python.org/issue37330

Comment threadDoc/library/fileinput.rst Outdated

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed changes in imp.py and fileinput.py.

Comment threadDoc/whatsnew/3.9.rst Outdated
Comment threadDoc/library/codecs.rst Outdated
Comment threadDoc/library/functions.rst Outdated
Comment threadDoc/library/fileinput.rst Outdated
Comment threadLib/test/test_fileinput.py Outdated
@bedevere-bot

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@tirkarthi

tirkarthi commented Jun 18, 2019

Copy link
Copy Markdown
Member

imp.py also does a similar check for U to be valid in

ifmodeand (notmode.startswith(('r', 'U')) or'+'inmode):
but the module is deprecated and it would fail at open with similar ValueError that "U" is invalid so not sure if it needs to be changed.

Edit: Saw Serhiy's review about imp.py just after refresh.

open(), io.open(), codecs.open() and fileinput.FileInput no longer
accept "U" ("universal newline") in the file mode. This flag was
deprecated since Python 3.3.
@vstinner

Copy link
Copy Markdown
MemberAuthor

@tirkarthi@serhiy-storchaka: I made requested changes.

@vstinner

Copy link
Copy Markdown
MemberAuthor

Oh, the Doc job of Travis CI fails with:

Sphinx parallel build error:
ValueError: invalid mode: 'rU'

Sphinx still uses rU mode.

@vstinner

Copy link
Copy Markdown
MemberAuthor

Sphinx issue comes from docutils:

 Exception occurred:
File "/home/vstinner/prog/python/master/Doc/venv/lib/python3.9/site-packages/docutils/io.py", line 245, in __init__
self.source = open(source_path, mode, **kwargs)
ValueError: invalid mode: 'rU'

Extract of the code, it seems to contain a copy of fileinput.FileInput:

class FileInput(Input):
def __init__(self, source=None, source_path=None,
encoding=None, error_handler='strict',
autoclose=True, mode='rU', **kwargs):
...
if source is None:
if source_path:
...
try:
self.source = open(source_path, mode, **kwargs)
except IOError as error:
raise InputError(error.errno, error.strerror, source_path)

@vstinner

Copy link
Copy Markdown
MemberAuthor

I reported the docutils issue to docutils bug tracker with a patch: https://sourceforge.net/p/docutils/bugs/363/

@vstinner

Copy link
Copy Markdown
MemberAuthor

This PR cannot be merged because it breaks the Python CI because of docutils: https://bugs.python.org/issue37330#msg346219

I prefer to close this PR right now. I will not be available next weeks, so I prefer to close the PR. I may reopen it later, once docutils is fixed.

@tirkarthi

Copy link
Copy Markdown
Member

@vstinner docutils 0.15 was released on July 21 which has the patch for 'U' mode. The current build config uses docutils>=0.12 in requirements so docutils 0.15 is used in the builds which and hence should be fix the issue.

@vstinner

Copy link
Copy Markdown
MemberAuthor

@vstinner docutils 0.15 was released on July 21 which has the patch for 'U' mode. The current build config uses docutils>=0.12 in requirements so docutils 0.15 is used in the builds which and hence should be fix the issue.

Nice. I tried to reopen the issue after I rebased my branch, but I made a mistake and I'm no longer able to open the PR. So I created PR #16959 instead.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@vstinner@bedevere-bot@tirkarthi@serhiy-storchaka@the-knights-who-say-ni