mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	GH-128520: pathlib ABCs: validate magic_open() arguments (#131617)
				
					
				
			When `pathlib._os.magic_open()` is called to open a path in binary mode, raise `ValueError` if any of the *encoding*, *errors* or *newline* arguments are given. This matches the `open()` built-in.
This commit is contained in:
		
							parent
							
								
									fbfb0e1f6e
								
							
						
					
					
						commit
						d716ea34cb
					
				
					 3 changed files with 12 additions and 0 deletions
				
			
		|  | @ -186,6 +186,12 @@ def magic_open(path, mode='r', buffering=-1, encoding=None, errors=None, | |||
|             pass | ||||
|         else: | ||||
|             return attr(path, buffering, encoding, errors, newline) | ||||
|     elif encoding is not None: | ||||
|         raise ValueError("binary mode doesn't take an encoding argument") | ||||
|     elif errors is not None: | ||||
|         raise ValueError("binary mode doesn't take an errors argument") | ||||
|     elif newline is not None: | ||||
|         raise ValueError("binary mode doesn't take a newline argument") | ||||
| 
 | ||||
|     try: | ||||
|         attr = getattr(cls, f'__open_{mode}b__') | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barney Gale
						Barney Gale