Skip to content

Conversation

rowillia
Copy link
Contributor

@rowillia rowillia commented May 22, 2017

FileInput fails if a single PathLike is passed in as files due to attempting to wrap it in a tuple:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/fileinput.py", line 198, in __init__
    files = tuple(files)
TypeError: 'PosixPath' object is not iterable

… `files`

Fixes

bpo-30432: FileInput doesn't accept PathLike objects for file names
@rowillia rowillia force-pushed the fix_fileinput_and_pathlib branch from 9ab6156 to c1d3367 Compare May 22, 2017 23:08
@rowillia rowillia changed the title Allow FileInput to accept a single PathLike object as a parameter for files bpo-30432: FileInput doesn't accept PathLike objects for file names May 22, 2017
Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

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

LGTM save for nits. You can fix them if you feel like it.

Lib/fileinput.py Outdated
mode="r", openhook=None):
if isinstance(files, str):
files = (files,)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spurious vertical whitespace

Lib/fileinput.py Outdated

elif isinstance(files, os.PathLike):
files = (os.fspath(files), )

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ditto

t1 = None
try:
t1 = Path(writeTmp(1, ["Pathlib file."]))
fi = FileInput(t1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the other tests use with FileInput(...) so it gets closed even if an assertion fails.

@ambv ambv merged commit 002665a into python:master May 23, 2017
@ambv
Copy link
Contributor

ambv commented May 23, 2017

We need to update Misc/ACKS, this can be a separate pull request.

@ambv
Copy link
Contributor

ambv commented May 23, 2017

Thank you! ✨ 🍰 ✨

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.

2 participants