Commit e23bd221 authored by Jason Madden's avatar Jason Madden

Cleanups

parent 0718a45e
...@@ -45,7 +45,7 @@ class _Base(Persistent): ...@@ -45,7 +45,7 @@ class _Base(Persistent):
# If they're NOT around, we don't need to do any of the # If they're NOT around, we don't need to do any of the
# special pickle support to make Python versions look like # special pickle support to make Python versions look like
# C---we just rename the classes. By not defining these methods, # C---we just rename the classes. By not defining these methods,
# we can (theoretically) regain a bit of speed. # we can (theoretically) avoid a bit of a slowdown.
# If the C extensions are around, we do need these methods, but # If the C extensions are around, we do need these methods, but
# these classes are unlikely to be used in production anyway. # these classes are unlikely to be used in production anyway.
__import__('BTrees._OOBTree') __import__('BTrees._OOBTree')
...@@ -54,7 +54,6 @@ class _Base(Persistent): ...@@ -54,7 +54,6 @@ class _Base(Persistent):
else: else:
def __reduce__(self): def __reduce__(self):
# Swap out the type constructor for the C version, if present. # Swap out the type constructor for the C version, if present.
type_self = type(self)
func, typ_gna, state = Persistent.__reduce__(self) func, typ_gna, state = Persistent.__reduce__(self)
# We ignore the returned type altogether in favor of # We ignore the returned type altogether in favor of
# our calculated class (which allows subclasses but replaces our exact # our calculated class (which allows subclasses but replaces our exact
...@@ -1571,7 +1570,7 @@ def _fix_pickle(mod_dict, mod_name): ...@@ -1571,7 +1570,7 @@ def _fix_pickle(mod_dict, mod_name):
except KeyError: except KeyError:
if name == 'TreeIterator': if name == 'TreeIterator':
# Optional # Optional
break continue
raise raise
raw_type = mod_dict[raw_name] # Could be C or Python raw_type = mod_dict[raw_name] # Could be C or Python
......
...@@ -263,9 +263,12 @@ class Base(object): ...@@ -263,9 +263,12 @@ class Base(object):
# Issue #2: Make sure our class swizzling doesn't break # Issue #2: Make sure our class swizzling doesn't break
# pickling subclasses # pickling subclasses
global PickleSubclass # XXX: Has to be global to pickle, but this prevents running tests in parallel # We need a globally named subclass for pickle, but it needs
class PickleSubclass(type(self._makeOne())): # to be unique in case tests run in parallel
pass base_class = type(self._makeOne())
class_name = 'PickleSubclassOf' + base_class.__name__
PickleSubclass = type(class_name, (base_class,), {})
globals()[class_name] = PickleSubclass
import pickle import pickle
loaded = pickle.loads(pickle.dumps(PickleSubclass())) loaded = pickle.loads(pickle.dumps(PickleSubclass()))
...@@ -879,17 +882,12 @@ class BTreeTests(MappingBase): ...@@ -879,17 +882,12 @@ class BTreeTests(MappingBase):
def _getTargetClass(self): def _getTargetClass(self):
# Most of the subclasses override _makeOne and not # Most of the subclasses override _makeOne and not
# _getTargetClass, so we can get the type that way. # _getTargetClass, so we can get the type that way.
# TODO: This could change for less repetition in the subclasses,
# using the name of the class to import the module and find
# the type.
if type(self)._makeOne is not BTreeTests._makeOne: if type(self)._makeOne is not BTreeTests._makeOne:
return type(self._makeOne()) return type(self._makeOne())
raise NotImplementedError()
# Derive the class from the test case name, if not
# overridden
name = self.__class__.__name__
type_name = name[:-4]
mod_name = 'BTrees.%s' % (type_name if not type_name.endswith("Py") else type_name[:-2])
mod = __import__(mod_name, fromlist=['ignored'])
return getattr(mod, type_name)
def _makeOne(self, *args): def _makeOne(self, *args):
return self._getTargetClass()(*args) return self._getTargetClass()(*args)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
https://github.com/zopefoundation/BTrees/issues/19 https://github.com/zopefoundation/BTrees/issues/19
- Unpickling empty BTrees in a pure-Python environment no longer - Unpickling empty BTrees in a pure-Python environment no longer
creates invalid objects that faile with ``AttributeError``. creates invalid objects that fail with ``AttributeError``.
4.2.0 (2015-11-13) 4.2.0 (2015-11-13)
------------------ ------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment