Skip to content

Commit 4600bb1

Browse files
committed
Fixed persistent object construction on subclassing.
1 parent d412697 commit 4600bb1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

CHANGES.txt

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ In next release ...
55

66
Bugfixes:
77

8+
- Persistent subclasses now correctly call ``__init__`` on
9+
construction.
10+
811
- Add support for ``__slots__``.
912

1013
0.3 (2012-02-02)

src/dobbin/persistent.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,24 @@ class Persistent(object):
6060
_p_resolve_conflict = None
6161

6262
def __new__(cls, *args, **kwargs):
63-
for base in cls.__mro__:
64-
if base.__new__ is cls.__new__:
65-
continue
66-
try:
67-
inst = base.__new__(cls)
68-
except TypeError:
69-
continue
70-
break
63+
bases = cls.__mro__
64+
try:
65+
index = bases.index(Local)
66+
except ValueError:
67+
for base in bases:
68+
if base.__new__ is cls.__new__:
69+
continue
70+
factory = base.__new__
71+
break
72+
else:
73+
factory = object.__new__
7174
else:
72-
raise TypeError("Can't create object of type %s." % repr(cls))
75+
cls = bases[index + 1]
76+
factory = object.__new__
7377

78+
inst = factory(cls)
7479
checkout(inst)
80+
inst.__init__(*args, **kwargs)
7581
return inst
7682

7783
def __deepcopy__(self, memo):

0 commit comments

Comments
 (0)