Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def _readline(self):
else:
if self._inplace:
self._backupfilename = (
self._filename + (self._backup or ".bak"))
os.fspath(self._filename) + (self._backup or ".bak"))
try:
os.unlink(self._backupfilename)
except OSError:
Expand Down
13 changes: 13 additions & 0 deletions 13 Lib/test/test_fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,19 @@ def test_pathlib_file(self):
finally:
remove_tempfiles(t1)

def test_pathlib_file_inplace(self):
t1 = None
try:
t1 = Path(writeTmp(1, ['Pathlib file.']))
with FileInput(t1, inplace=True) as fi:
line = fi.readline()
self.assertEqual(line, 'Pathlib file.')
print('Modified %s' % line)
with open(t1) as f:
self.assertEqual(f.read(), 'Modified Pathlib file.\n')
finally:
remove_tempfiles(t1)


class MockFileInput:
"""A class that mocks out fileinput.FileInput for use during unit tests"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``fileinput.FileInput(files, inplace=True)`` when ``files`` contain
``pathlib.Path`` objects.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.