Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
266e4548
Commit
266e4548
authored
May 21, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure the last line has a trailing newline #8782
parent
dd59f1bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/linecache.py
Lib/linecache.py
+2
-0
Lib/test/test_linecache.py
Lib/test/test_linecache.py
+12
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/linecache.py
View file @
266e4548
...
...
@@ -133,6 +133,8 @@ def updatecache(filename, module_globals=None):
except
IOError
,
msg
:
## print '*** Cannot open', fullname, ':', msg
return
[]
if
lines
and
not
lines
[
-
1
].
endswith
(
'
\
n
'
):
lines
[
-
1
]
+=
'
\
n
'
size
,
mtime
=
stat
.
st_size
,
stat
.
st_mtime
cache
[
filename
]
=
size
,
mtime
,
lines
,
fullname
return
lines
Lib/test/test_linecache.py
View file @
266e4548
...
...
@@ -31,6 +31,11 @@ a = f()
'''
SOURCE_3
=
'''
def f():
return 3'''
# No ending newline
class
LineCacheTests
(
unittest
.
TestCase
):
def
test_getline
(
self
):
...
...
@@ -63,6 +68,13 @@ class LineCacheTests(unittest.TestCase):
empty
=
linecache
.
getlines
(
'a/b/c/__init__.py'
)
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
):
cached
=
[]
for
entry
in
TESTS
:
...
...
Misc/NEWS
View file @
266e4548
...
...
@@ -29,6 +29,9 @@ C-API
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
comparing to a non-mapping.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment