Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit405a921

Browse files
committed
fix linecache
1 parent645a609 commit405a921

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

‎Lib/linecache.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def checkcache(filename=None):
7373
exceptOSError:
7474
cache.pop(filename,None)
7575
continue
76+
exceptValueError:
77+
# ValueError may happen on Windows platforms for long paths.
78+
# In this case, we assume that we could not just read the file.
79+
#
80+
# See: https://github.com/python/cpython/issues/122170.
81+
ifos.name=='nt':
82+
cache.pop(filename,None)
83+
continue
84+
raise# this should not happen on other platforms
7685
ifsize!=stat.st_sizeormtime!=stat.st_mtime:
7786
cache.pop(filename,None)
7887

@@ -137,8 +146,15 @@ def updatecache(filename, module_globals=None):
137146
break
138147
exceptOSError:
139148
pass
149+
exceptValueError:
150+
ifos.name!='nt':
151+
raise# this should not happen on other platforms
140152
else:
141153
return []
154+
exceptValueError:
155+
ifos.name!='nt':
156+
raise# this should not happen on other platforms
157+
return []
142158
try:
143159
withtokenize.open(fullname)asfp:
144160
lines=fp.readlines()

‎Lib/test/test_linecache.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ def test_loader(self):
280280
self.assertEqual(linecache.getlines(filename,module_globals),
281281
['source for x.y.z\n'])
282282

283+
@unittest.skipIf(os.name!='nt','Windows only')
284+
deftest_windows_long_filename(self):
285+
linecache.clearcache()
286+
line=linecache.getline('a'*9999,1)
287+
self.assertEqual(line,'')
288+
283289

284290
classLineCacheInvalidationTests(unittest.TestCase):
285291
defsetUp(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp