mirror of
				https://github.com/python/cpython.git
				synced 2025-10-26 11:14:33 +00:00 
			
		
		
		
	Pickler.save(): Fix for SF bug #494904: Cannot pickle a class with a
metaclass, reported by Dan Parisien. Objects that are instances of custom metaclasses, i.e. whose class is a subclass of 'type', should be pickled the same as new-style classes (objects whose class is 'type'). This can't be done through a dispatch table entry, and the __reduce__ trick doesn't work for these, since it finds the unbound __reduce__ for instances of the class (inherited from 'object'). So check explicitly using issubclass().
This commit is contained in:
		
							parent
							
								
									5935ff07be
								
							
						
					
					
						commit
						f048a8f6d7
					
				
					 1 changed files with 4 additions and 0 deletions
				
			
		|  | @ -163,6 +163,10 @@ def save(self, object, pers_save = 0): | ||||||
|         try: |         try: | ||||||
|             f = self.dispatch[t] |             f = self.dispatch[t] | ||||||
|         except KeyError: |         except KeyError: | ||||||
|  |             if issubclass(t, TypeType): | ||||||
|  |                 self.save_global(object) | ||||||
|  |                 return | ||||||
|  | 
 | ||||||
|             pid = self.inst_persistent_id(object) |             pid = self.inst_persistent_id(object) | ||||||
|             if pid is not None: |             if pid is not None: | ||||||
|                 self.save_pers(pid) |                 self.save_pers(pid) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum