mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Patch #1635454: the csv.DictWriter class now includes the offending
field names in its exception message if you try to write a record with a dictionary containing fields not in the CSV field names list.
This commit is contained in:
		
							parent
							
								
									ceede5c359
								
							
						
					
					
						commit
						94fe3f58d0
					
				
					 2 changed files with 8 additions and 3 deletions
				
			
		|  | @ -115,9 +115,10 @@ def __init__(self, f, fieldnames, restval="", extrasaction="raise", | ||||||
| 
 | 
 | ||||||
|     def _dict_to_list(self, rowdict): |     def _dict_to_list(self, rowdict): | ||||||
|         if self.extrasaction == "raise": |         if self.extrasaction == "raise": | ||||||
|             for k in rowdict.keys(): |             wrong_fields = [k for k in rowdict if k not in self.fieldnames] | ||||||
|                 if k not in self.fieldnames: |             if wrong_fields: | ||||||
|                     raise ValueError, "dict contains fields not in fieldnames" |                 raise ValueError("dict contains fields not in fieldnames: " + | ||||||
|  |                                  ", ".join(wrong_fields)) | ||||||
|         return [rowdict.get(key, self.restval) for key in self.fieldnames] |         return [rowdict.get(key, self.restval) for key in self.fieldnames] | ||||||
| 
 | 
 | ||||||
|     def writerow(self, rowdict): |     def writerow(self, rowdict): | ||||||
|  |  | ||||||
|  | @ -168,6 +168,10 @@ Core and builtins | ||||||
| Library | Library | ||||||
| ------- | ------- | ||||||
| 
 | 
 | ||||||
|  | - Patch #1635454: the csv.DictWriter class now includes the offending | ||||||
|  |   field names in its exception message if you try to write a record with | ||||||
|  |   a dictionary containing fields not in the CSV field names list. | ||||||
|  | 
 | ||||||
| - Patch #1668100: urllib2 now correctly raises URLError instead of | - Patch #1668100: urllib2 now correctly raises URLError instead of | ||||||
|   OSError if accessing a local file via the file:// protocol fails. |   OSError if accessing a local file via the file:// protocol fails. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Georg Brandl
						Georg Brandl