mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig Citro.
This commit is contained in:
commit
5a688dbf97
5 changed files with 40 additions and 13 deletions
|
@ -297,20 +297,20 @@ class _Pickler:
|
|||
f(self, obj) # Call unbound method with explicit self
|
||||
return
|
||||
|
||||
# Check for a class with a custom metaclass; treat as regular class
|
||||
try:
|
||||
issc = issubclass(t, type)
|
||||
except TypeError: # t is not a class (old Boost; see SF #502085)
|
||||
issc = 0
|
||||
if issc:
|
||||
self.save_global(obj)
|
||||
return
|
||||
|
||||
# Check copyreg.dispatch_table
|
||||
reduce = dispatch_table.get(t)
|
||||
if reduce:
|
||||
rv = reduce(obj)
|
||||
else:
|
||||
# Check for a class with a custom metaclass; treat as regular class
|
||||
try:
|
||||
issc = issubclass(t, type)
|
||||
except TypeError: # t is not a class (old Boost; see SF #502085)
|
||||
issc = False
|
||||
if issc:
|
||||
self.save_global(obj)
|
||||
return
|
||||
|
||||
# Check for a __reduce_ex__ method, fall back to __reduce__
|
||||
reduce = getattr(obj, "__reduce_ex__", None)
|
||||
if reduce:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue