mirror of
				https://github.com/python/cpython.git
				synced 2025-10-27 03:34:32 +00:00 
			
		
		
		
	Add __class_getitem__ to csv.DictReader and csv.DictWriter (#92393)
This commit is contained in:
		
							parent
							
								
									3680ebed7f
								
							
						
					
					
						commit
						5ed5c56123
					
				
					 4 changed files with 12 additions and 1 deletions
				
			
		|  | @ -4,6 +4,7 @@ | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import re | import re | ||||||
|  | import types | ||||||
| from _csv import Error, __version__, writer, reader, register_dialect, \ | from _csv import Error, __version__, writer, reader, register_dialect, \ | ||||||
|                  unregister_dialect, get_dialect, list_dialects, \ |                  unregister_dialect, get_dialect, list_dialects, \ | ||||||
|                  field_size_limit, \ |                  field_size_limit, \ | ||||||
|  | @ -126,6 +127,8 @@ def __next__(self): | ||||||
|                 d[key] = self.restval |                 d[key] = self.restval | ||||||
|         return d |         return d | ||||||
| 
 | 
 | ||||||
|  |     __class_getitem__ = classmethod(types.GenericAlias) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class DictWriter: | class DictWriter: | ||||||
|     def __init__(self, f, fieldnames, restval="", extrasaction="raise", |     def __init__(self, f, fieldnames, restval="", extrasaction="raise", | ||||||
|  | @ -156,6 +159,8 @@ def writerow(self, rowdict): | ||||||
|     def writerows(self, rowdicts): |     def writerows(self, rowdicts): | ||||||
|         return self.writer.writerows(map(self._dict_to_list, rowdicts)) |         return self.writer.writerows(map(self._dict_to_list, rowdicts)) | ||||||
| 
 | 
 | ||||||
|  |     __class_getitem__ = classmethod(types.GenericAlias) | ||||||
|  | 
 | ||||||
| # Guard Sniffer's type checking against builds that exclude complex() | # Guard Sniffer's type checking against builds that exclude complex() | ||||||
| try: | try: | ||||||
|     complex |     complex | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ | ||||||
| from concurrent.futures.thread import _WorkItem | from concurrent.futures.thread import _WorkItem | ||||||
| from contextlib import AbstractContextManager, AbstractAsyncContextManager | from contextlib import AbstractContextManager, AbstractAsyncContextManager | ||||||
| from contextvars import ContextVar, Token | from contextvars import ContextVar, Token | ||||||
|  | from csv import DictReader, DictWriter | ||||||
| from dataclasses import Field | from dataclasses import Field | ||||||
| from functools import partial, partialmethod, cached_property | from functools import partial, partialmethod, cached_property | ||||||
| from graphlib import TopologicalSorter | from graphlib import TopologicalSorter | ||||||
|  | @ -122,7 +123,8 @@ class BaseTest(unittest.TestCase): | ||||||
|                      WeakSet, ReferenceType, ref, |                      WeakSet, ReferenceType, ref, | ||||||
|                      ShareableList, |                      ShareableList, | ||||||
|                      Future, _WorkItem, |                      Future, _WorkItem, | ||||||
|                      Morsel] |                      Morsel, | ||||||
|  |                      DictReader, DictWriter] | ||||||
|     if ctypes is not None: |     if ctypes is not None: | ||||||
|         generic_types.extend((ctypes.Array, ctypes.LibraryLoader)) |         generic_types.extend((ctypes.Array, ctypes.LibraryLoader)) | ||||||
|     if ValueProxy is not None: |     if ValueProxy is not None: | ||||||
|  |  | ||||||
|  | @ -1228,6 +1228,7 @@ Alessandro Moura | ||||||
| Pablo Mouzo | Pablo Mouzo | ||||||
| Mher Movsisyan | Mher Movsisyan | ||||||
| Ruslan Mstoi | Ruslan Mstoi | ||||||
|  | Marc Mueller | ||||||
| Valentina Mukhamedzhanova | Valentina Mukhamedzhanova | ||||||
| Michael Mulich | Michael Mulich | ||||||
| Sape Mullender | Sape Mullender | ||||||
|  |  | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | Add :meth:`~object.__class_getitem__` to  :class:`csv.DictReader` and | ||||||
|  | :class:`csv.DictWriter`, allowing them to be parameterized at runtime. | ||||||
|  | Patch by Marc Mueller. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marc Mueller
						Marc Mueller