mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	GH-125413: Revert addition of pathlib.Path.scandir() method (#127377)
				
					
				
			Remove documentation for `pathlib.Path.scandir()`, and rename the method to `_scandir()`. In the private pathlib ABCs, make `iterdir()` abstract and call it from `_scandir()`. It's not worthwhile to add this method at the moment - see discussion: https://discuss.python.org/t/ergonomics-of-new-pathlib-path-scandir/71721 Co-authored-by: Steve Dower <steve.dower@microsoft.com>
This commit is contained in:
		
							parent
							
								
									f4f530804b
								
							
						
					
					
						commit
						8b3cccf3f9
					
				
					 7 changed files with 22 additions and 85 deletions
				
			
		|  | @ -94,7 +94,7 @@ class PathGlobber(_GlobberBase): | |||
| 
 | ||||
|     lexists = operator.methodcaller('exists', follow_symlinks=False) | ||||
|     add_slash = operator.methodcaller('joinpath', '') | ||||
|     scandir = operator.methodcaller('scandir') | ||||
|     scandir = operator.methodcaller('_scandir') | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def concat_path(path, text): | ||||
|  | @ -632,13 +632,14 @@ def write_text(self, data, encoding=None, errors=None, newline=None): | |||
|         with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f: | ||||
|             return f.write(data) | ||||
| 
 | ||||
|     def scandir(self): | ||||
|         """Yield os.DirEntry objects of the directory contents. | ||||
|     def _scandir(self): | ||||
|         """Yield os.DirEntry-like objects of the directory contents. | ||||
| 
 | ||||
|         The children are yielded in arbitrary order, and the | ||||
|         special entries '.' and '..' are not included. | ||||
|         """ | ||||
|         raise UnsupportedOperation(self._unsupported_msg('scandir()')) | ||||
|         import contextlib | ||||
|         return contextlib.nullcontext(self.iterdir()) | ||||
| 
 | ||||
|     def iterdir(self): | ||||
|         """Yield path objects of the directory contents. | ||||
|  | @ -646,9 +647,7 @@ def iterdir(self): | |||
|         The children are yielded in arbitrary order, and the | ||||
|         special entries '.' and '..' are not included. | ||||
|         """ | ||||
|         with self.scandir() as entries: | ||||
|             names = [entry.name for entry in entries] | ||||
|         return map(self.joinpath, names) | ||||
|         raise UnsupportedOperation(self._unsupported_msg('iterdir()')) | ||||
| 
 | ||||
|     def _glob_selector(self, parts, case_sensitive, recurse_symlinks): | ||||
|         if case_sensitive is None: | ||||
|  | @ -698,7 +697,7 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False): | |||
|             if not top_down: | ||||
|                 paths.append((path, dirnames, filenames)) | ||||
|             try: | ||||
|                 with path.scandir() as entries: | ||||
|                 with path._scandir() as entries: | ||||
|                     for entry in entries: | ||||
|                         name = entry.name | ||||
|                         try: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barney Gale
						Barney Gale