mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	GH-125413: pathlib ABCs: use caching path.info.exists() when globbing (#130422)
				
					
				
			Call `ReadablePath.info.exists()` rather than `ReadablePath.exists()` when globbing so that we use (or populate) the `info` cache.
This commit is contained in:
		
							parent
							
								
									d73d69e232
								
							
						
					
					
						commit
						48c84a400a
					
				
					 3 changed files with 9 additions and 10 deletions
				
			
		|  | @ -533,7 +533,9 @@ class _PathGlobber(_GlobberBase): | ||||||
|     """Provides shell-style pattern matching and globbing for pathlib paths. |     """Provides shell-style pattern matching and globbing for pathlib paths. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|     lexists = operator.methodcaller('exists', follow_symlinks=False) |     @staticmethod | ||||||
|  |     def lexists(path): | ||||||
|  |         return path.info.exists(follow_symlinks=False) | ||||||
| 
 | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def scandir(path): |     def scandir(path): | ||||||
|  |  | ||||||
|  | @ -316,15 +316,12 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False): | ||||||
|                 paths.append((path, dirnames, filenames)) |                 paths.append((path, dirnames, filenames)) | ||||||
|             try: |             try: | ||||||
|                 for child in path.iterdir(): |                 for child in path.iterdir(): | ||||||
|                     try: |  | ||||||
|                     if child.info.is_dir(follow_symlinks=follow_symlinks): |                     if child.info.is_dir(follow_symlinks=follow_symlinks): | ||||||
|                         if not top_down: |                         if not top_down: | ||||||
|                             paths.append(child) |                             paths.append(child) | ||||||
|                         dirnames.append(child.name) |                         dirnames.append(child.name) | ||||||
|                     else: |                     else: | ||||||
|                         filenames.append(child.name) |                         filenames.append(child.name) | ||||||
|                     except OSError: |  | ||||||
|                         filenames.append(child.name) |  | ||||||
|             except OSError as error: |             except OSError as error: | ||||||
|                 if on_error is not None: |                 if on_error is not None: | ||||||
|                     on_error(error) |                     on_error(error) | ||||||
|  |  | ||||||
|  | @ -1107,7 +1107,7 @@ def test_glob_posix(self): | ||||||
|         p = P(self.base) |         p = P(self.base) | ||||||
|         q = p / "FILEa" |         q = p / "FILEa" | ||||||
|         given = set(p.glob("FILEa")) |         given = set(p.glob("FILEa")) | ||||||
|         expect = {q} if q.exists() else set() |         expect = {q} if q.info.exists() else set() | ||||||
|         self.assertEqual(given, expect) |         self.assertEqual(given, expect) | ||||||
|         self.assertEqual(set(p.glob("FILEa*")), set()) |         self.assertEqual(set(p.glob("FILEa*")), set()) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barney Gale
						Barney Gale