File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,15 @@ def checkcache(filename=None):
73
73
except OSError :
74
74
cache .pop (filename , None )
75
75
continue
76
+ except ValueError :
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
+ if os .name == 'nt' :
82
+ cache .pop (filename , None )
83
+ continue
84
+ raise # this should not happen on other platforms
76
85
if size != stat .st_size or mtime != stat .st_mtime :
77
86
cache .pop (filename , None )
78
87
@@ -137,8 +146,15 @@ def updatecache(filename, module_globals=None):
137
146
break
138
147
except OSError :
139
148
pass
149
+ except ValueError :
150
+ if os .name != 'nt' :
151
+ raise # this should not happen on other platforms
140
152
else :
141
153
return []
154
+ except ValueError :
155
+ if os .name != 'nt' :
156
+ raise # this should not happen on other platforms
157
+ return []
142
158
try :
143
159
with tokenize .open (fullname ) as fp :
144
160
lines = fp .readlines ()
Original file line number Diff line number Diff line change @@ -280,6 +280,28 @@ def test_loader(self):
280
280
self .assertEqual (linecache .getlines (filename , module_globals ),
281
281
['source for x.y.z\n ' ])
282
282
283
+ def test_long_filename (self ):
284
+ # For POSIX platforms, an OSError will be raised and will take
285
+ # the usual path handling. For Windows platforms, a ValueError
286
+ # is raised instead but linecache will handle it as if it were
287
+ # an OSError in this case.
288
+ #
289
+ # See: https://github.com/python/cpython/issues/122170
290
+
291
+ linecache .clearcache ()
292
+ lines = linecache .updatecache ('a' * 9999 )
293
+ self .assertListEqual (lines , [])
294
+ self .assertNotIn ('a' * 9999 , linecache .cache )
295
+
296
+ # hack into the cache (it shouldn't be allowed
297
+ # but we never know what people do...)
298
+ linecache .cache ['smallname' ] = (0 , 1234 , [], 'a' * 9999 )
299
+ linecache .checkcache ('smallname' )
300
+ self .assertNotIn ('smallname' , linecache .cache )
301
+
302
+ # just to be sure that we did not mess with cache
303
+ linecache .clearcache ()
304
+
283
305
284
306
class LineCacheInvalidationTests (unittest .TestCase ):
285
307
def setUp (self ):
You can’t perform that action at this time.
0 commit comments