mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
ensure the last line has a trailing newline #8782
This commit is contained in:
parent
dd59f1bf92
commit
266e454866
3 changed files with 17 additions and 0 deletions
|
|
@ -133,6 +133,8 @@ def updatecache(filename, module_globals=None):
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
## print '*** Cannot open', fullname, ':', msg
|
## print '*** Cannot open', fullname, ':', msg
|
||||||
return []
|
return []
|
||||||
|
if lines and not lines[-1].endswith('\n'):
|
||||||
|
lines[-1] += '\n'
|
||||||
size, mtime = stat.st_size, stat.st_mtime
|
size, mtime = stat.st_size, stat.st_mtime
|
||||||
cache[filename] = size, mtime, lines, fullname
|
cache[filename] = size, mtime, lines, fullname
|
||||||
return lines
|
return lines
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ a = f()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
SOURCE_3 = '''
|
||||||
|
def f():
|
||||||
|
return 3''' # No ending newline
|
||||||
|
|
||||||
|
|
||||||
class LineCacheTests(unittest.TestCase):
|
class LineCacheTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_getline(self):
|
def test_getline(self):
|
||||||
|
|
@ -63,6 +68,13 @@ class LineCacheTests(unittest.TestCase):
|
||||||
empty = linecache.getlines('a/b/c/__init__.py')
|
empty = linecache.getlines('a/b/c/__init__.py')
|
||||||
self.assertEquals(empty, [])
|
self.assertEquals(empty, [])
|
||||||
|
|
||||||
|
def test_no_ending_newline(self):
|
||||||
|
self.addCleanup(support.unlink, support.TESTFN)
|
||||||
|
with open(support.TESTFN, "w") as fp:
|
||||||
|
fp.write(SOURCE_3)
|
||||||
|
lines = linecache.getlines(support.TESTFN)
|
||||||
|
self.assertEqual(lines, ["\n", "def f():\n", " return 3\n"])
|
||||||
|
|
||||||
def test_clearcache(self):
|
def test_clearcache(self):
|
||||||
cached = []
|
cached = []
|
||||||
for entry in TESTS:
|
for entry in TESTS:
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #8782: Add a trailing newline in linecache.updatecache to the last line
|
||||||
|
of files without one.
|
||||||
|
|
||||||
- Issue #8729: Return NotImplemented from collections.Mapping.__eq__ when
|
- Issue #8729: Return NotImplemented from collections.Mapping.__eq__ when
|
||||||
comparing to a non-mapping.
|
comparing to a non-mapping.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue