[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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-37330: open() no longer accept 'U' in file mode #14204

Closed
wants to merge 3 commits into from

Conversation

Copy link
Member

vstinner commented Jun 18, 2019

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

Copy link
Member

serhiy-storchaka left a comment

Needed changes in imp.py and fileinput.py.

Doc/whatsnew/3.9.rst Outdated Show resolved Hide resolved
Doc/library/codecs.rst Outdated Show resolved Hide resolved
Doc/library/functions.rst Outdated Show resolved Hide resolved
Doc/library/fileinput.rst Show resolved Hide resolved
Lib/test/test_fileinput.py Outdated Show resolved Hide resolved
Copy link

bedevere-bot commented Jun 18, 2019

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

Copy link
Member

tirkarthi commented Jun 18, 2019

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

if mode and (not mode.startswith(('r', 'U')) or '+' in mode):
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.
Copy link
Member Author

vstinner commented Jun 18, 2019

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

Copy link
Member Author

vstinner commented Jun 19, 2019

Oh, the Doc job of Travis CI fails with:

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

Sphinx still uses rU mode.

Copy link
Member Author

vstinner commented Jun 19, 2019

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)

Copy link
Member Author

vstinner commented Jun 20, 2019

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

Copy link
Member Author

vstinner commented Jul 16, 2019

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.

vstinner closed this Jul 16, 2019
Copy link
Member

tirkarthi commented Jul 22, 2019

@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.

Copy link
Member Author

vstinner commented Oct 27, 2019

@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 free to 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.

None yet

5 participants