-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-31281: Fix pathlib.Path incompatibility in fileinput #3208
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
Lib/fileinput.py
Outdated
@@ -330,7 +330,7 @@ def _readline(self): | |||
else: | |||
if self._inplace: | |||
self._backupfilename = ( | |||
self._filename + (self._backup or ".bak")) | |||
str(self._filename) + (self._backup or ".bak")) |
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.
os.fspath is preferred over str().
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.
@ericvsmith Updated.
35ef435
to
10792d1
Compare
This also needs tests. I don't know what the existing tests look like. |
fileinput otherwise works fine with pathlib.Path filenames, but when inplace is set to True, the Path object needs to be converted to a str first, or appending a str suffix with + would fail.
10792d1
to
590e228
Compare
@ericvsmith I added a test. |
* 'master' of https://github.com/python/cpython: (601 commits) remove check for bug last seem in Solaris 9 (python#3285) Change code owners for hashlib and ssl to the crypto team (python#3284) bpo-31281: Fix pathlib.Path incompatibility in fileinput (pythongh-3208) remove autoconf check for select() (python#3283) remove configure check for 'volatile' (python#3281) Add missing _sha3 module to Setup.dist (python#2395) bpo-12383: Also ignore __PYVENV_LAUNCHER__ (python#3278) bpo-9146: add the missing NEWS entry. (python#3275) Fix a c.f.as_completed() refleak previously introduced in bpo-27144 (python#3270) bpo-31185: Fixed miscellaneous errors in asyncio speedup module. (python#3076) remove a redundant lower in urllib.parse.urlsplit (python#3008) bpo-31323: Fix reference leak in test_ssl (python#3263) bpo-31250, test_asyncio: fix EventLoopTestsMixin.tearDown() (python#3264) bpo-31326: ProcessPoolExecutor waits for the call queue thread (python#3265) bpo-27144: concurrent.futures as_complete and map iterators do not keep reference to returned object (python#1560) bpo-31250, test_asyncio: fix dangling threads (python#3252) bpo-31217: Fix regrtest -R for small integer (python#3260) bpo-30096: Use ABC in abc reference examples (python#1220) bpo-30737: Update DevGuide links to new URL (pythonGH-3228) [Trivial] Remove now redundant assert (python#3245) ...
Fix fileinput with inplace=True to accept pathlib.Path objects.
fileinput
otherwise works fine withpathlib.Path
filenames, but wheninplace
is set toTrue
, thePath
object needs to be converted to astr
first, or appending astr
suffix with+
would fail:=>
https://bugs.python.org/issue31281