Skip to content

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

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

Closed
wants to merge 3 commits into from
Closed

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

wants to merge 3 commits into from

Conversation

vstinner
Copy link
Member

@vstinner 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 serhiy-storchaka left a comment

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.

@bedevere-bot
Copy link

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

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

vstinner added 2 commits June 19, 2019 00:40
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
Member Author

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

@vstinner
Copy link
Member Author

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
Member Author

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
Member Author

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

@vstinner
Copy link
Member Author

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 vstinner closed this Jul 16, 2019
@tirkarthi
Copy link
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
Member Author

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

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy