| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,8 +37,12 @@ def getlines(filename, module_globals=None): | |||
| 37 | 37 | ||
| 38 | 38 | if filename in cache: | |
| 39 | 39 | return cache[filename][2] | |
| 40 | - else: | ||
| 40 | + | ||
| 41 | + try: | ||
| 41 | 42 | return updatecache(filename, module_globals) | |
| 43 | + except MemoryError: | ||
| 44 | + clearcache() | ||
| 45 | + return [] | ||
| 42 | 46 | ||
| 43 | 47 | ||
| 44 | 48 | def checkcache(filename=None): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,8 +126,21 @@ def test_checkcache(self): | |||
| 126 | 126 | self.assertEqual(line, getline(source_name, index + 1)) | |
| 127 | 127 | source_list.append(line) | |
| 128 | 128 | ||
| 129 | - def test_main(): | ||
| 130 | - support.run_unittest(LineCacheTests) | ||
| 129 | + def test_memoryerror(self): | ||
| 130 | + lines = linecache.getlines(FILENAME) | ||
| 131 | + self.assertTrue(lines) | ||
| 132 | + def raise_memoryerror(*args, **kwargs): | ||
| 133 | + raise MemoryError | ||
| 134 | + with support.swap_attr(linecache, 'updatecache', raise_memoryerror): | ||
| 135 | + lines2 = linecache.getlines(FILENAME) | ||
| 136 | + self.assertEqual(lines2, lines) | ||
| 137 | + | ||
| 138 | + linecache.clearcache() | ||
| 139 | + with support.swap_attr(linecache, 'updatecache', raise_memoryerror): | ||
| 140 | + lines3 = linecache.getlines(FILENAME) | ||
| 141 | + self.assertEqual(lines3, []) | ||
| 142 | + self.assertEqual(linecache.getlines(FILENAME), lines) | ||
| 143 | + | ||
| 131 | 144 | ||
| 132 | 145 | if __name__ == "__main__": | |
| 133 | - test_main() | ||
| 146 | + unittest.main() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,9 @@ Core and Builtins | |||
| 21 | 21 | Library | |
| 22 | 22 | ------- | |
| 23 | 23 | ||
| 24 | + - Issue #23838: linecache now clears the cache and returns an empty result on | ||
| 25 | + MemoryError. | ||
| 26 | + | ||
| 24 | 27 | - Issue #18473: Fixed 2to3 and 3to2 compatible pickle mappings. Fixed | |
| 25 | 28 | ambigious reverse mappings. Added many new mappings. Import mapping is no | |
| 26 | 29 | longer applied to modules already mapped with full name mapping. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments