-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
bpo-30432: FileInput doesn't accept PathLike objects for file names #1732
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
Conversation
… `files` Fixes bpo-30432: FileInput doesn't accept PathLike objects for file names
9ab6156
to
c1d3367
Compare
files
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.
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,) | ||
|
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.
nit: spurious vertical whitespace
Lib/fileinput.py
Outdated
|
||
elif isinstance(files, os.PathLike): | ||
files = (os.fspath(files), ) | ||
|
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.
nit: ditto
Lib/test/test_fileinput.py
Outdated
t1 = None | ||
try: | ||
t1 = Path(writeTmp(1, ["Pathlib file."])) | ||
fi = FileInput(t1) |
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.
nit: the other tests use with FileInput(...)
so it gets closed even if an assertion fails.
We need to update Misc/ACKS, this can be a separate pull request. |
Thank you! ✨ 🍰 ✨ |
FileInput fails if a single
PathLike
is passed in asfiles
due to attempting to wrap it in a tuple: