Merge lp:~cjwatson/storm/py3-metaclass into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 523
Proposed branch: lp:~cjwatson/storm/py3-metaclass
Merge into: lp:storm
Diff against target: 190 lines (+30/-22)
6 files modified
storm/base.py (+3/-2)
storm/sqlobject.py (+3/-2)
tests/info.py (+3/-2)
tests/mocker.py (+9/-6)
tests/properties.py (+4/-2)
tests/store/base.py (+8/-8)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-metaclass
Reviewer Review Type Date Requested Status
Simon Poirier (community) Approve
Review via email: mp+371158@code.launchpad.net

Commit message

Use six.with_metaclass to support Python 3's metaclass syntax.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) wrote :

For what it's worth, this definitely looks plausible and reasonable to me, but I'm not currently familiar enough with metaclasses, metaclass changes between 2/3, and/or Storm's usage thereof, to necessarily give a _positive_ review

Revision history for this message
Simon Poirier (simpoir) wrote :

+1 exactly what I'd expect.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/base.py'
2--- storm/base.py 2019-06-05 11:41:07 +0000
3+++ storm/base.py 2019-08-11 09:00:12 +0000
4@@ -20,18 +20,19 @@
5 #
6 from __future__ import print_function
7
8+import six
9+
10 from storm.properties import PropertyPublisherMeta
11
12
13 __all__ = ["Storm"]
14
15
16-class Storm(object):
17+class Storm(six.with_metaclass(PropertyPublisherMeta, object)):
18 """An optional base class for objects stored in a Storm Store.
19
20 It causes your subclasses to be associated with a Storm
21 PropertyRegistry. It is necessary to use this if you want to
22 specify References with strings.
23 """
24- __metaclass__ = PropertyPublisherMeta
25
26
27=== modified file 'storm/sqlobject.py'
28--- storm/sqlobject.py 2019-06-05 11:41:07 +0000
29+++ storm/sqlobject.py 2019-08-11 09:00:12 +0000
30@@ -28,6 +28,8 @@
31 import re
32 import warnings
33
34+import six
35+
36 from storm.properties import (
37 RawStr, Int, Bool, Float, DateTime, Date, TimeDelta)
38 from storm.references import Reference, ReferenceSet
39@@ -261,7 +263,7 @@
40 return getattr(self._cls, attr)
41
42
43-class SQLObjectBase(Storm):
44+class SQLObjectBase(six.with_metaclass(SQLObjectMeta, Storm)):
45 """The root class of all SQLObject-emulating classes in your application.
46
47 The general strategy for using Storm's SQLObject emulation layer
48@@ -271,7 +273,6 @@
49 even be implemented as returning a global L{Store} instance. Then
50 all database classes should subclass that class.
51 """
52- __metaclass__ = SQLObjectMeta
53
54 q = DotQ()
55 _SO_creating = False
56
57=== modified file 'tests/info.py'
58--- tests/info.py 2019-06-05 11:41:07 +0000
59+++ tests/info.py 2019-08-11 09:00:12 +0000
60@@ -23,6 +23,8 @@
61 from weakref import ref
62 import gc
63
64+import six
65+
66 from storm.exceptions import ClassInfoError
67 from storm.properties import Property
68 from storm.variables import Variable
69@@ -571,8 +573,7 @@
70 cls = type.__new__(meta_cls, name, bases, dict)
71 cls.__storm_table__ = "HAH! GOTCH YA!"
72 return cls
73- class Class(object):
74- __metaclass__ = MetaClass
75+ class Class(six.with_metaclass(MetaClass, object)):
76 __storm_table__ = "table"
77 prop1 = Property("column1", primary=True)
78 Alias = ClassAlias(Class, "USE_THIS")
79
80=== modified file 'tests/mocker.py'
81--- tests/mocker.py 2019-06-07 17:14:33 +0000
82+++ tests/mocker.py 2019-08-11 09:00:12 +0000
83@@ -13,6 +13,7 @@
84 import os
85 import gc
86
87+import six
88 from six.moves import builtins
89
90
91@@ -324,7 +325,14 @@
92 return bound_method
93
94
95-class MockerBase(object):
96+class MockerMeta(type):
97+
98+ def __init__(self, name, bases, dict):
99+ # Make independent lists on each subclass, inheriting from parent.
100+ self._recorders = list(getattr(self, "_recorders", ()))
101+
102+
103+class MockerBase(six.with_metaclass(MockerMeta, object)):
104 """Controller of mock objects.
105
106 A mocker instance is used to command recording and replay of
107@@ -380,11 +388,6 @@
108 # For convenience only.
109 on = expect
110
111- class __metaclass__(type):
112- def __init__(self, name, bases, dict):
113- # Make independent lists on each subclass, inheriting from parent.
114- self._recorders = list(getattr(self, "_recorders", ()))
115-
116 def __init__(self):
117 self._recorders = self._recorders[:]
118 self._events = []
119
120=== modified file 'tests/properties.py'
121--- tests/properties.py 2019-06-05 11:41:07 +0000
122+++ tests/properties.py 2019-08-11 09:00:12 +0000
123@@ -25,6 +25,8 @@
124 import gc
125 import uuid
126
127+import six
128+
129 from storm.compat import json
130 from storm.exceptions import NoneError, PropertyPathError
131 from storm.properties import PropertyPublisherMeta
132@@ -986,8 +988,8 @@
133 def setUp(self):
134 TestHelper.setUp(self)
135
136- class Base(object):
137- __metaclass__ = PropertyPublisherMeta
138+ class Base(six.with_metaclass(PropertyPublisherMeta, object)):
139+ pass
140
141 class Class(Base):
142 __storm_table__ = "mytable"
143
144=== modified file 'tests/store/base.py'
145--- tests/store/base.py 2019-06-07 17:14:33 +0000
146+++ tests/store/base.py 2019-08-11 09:00:12 +0000
147@@ -4454,8 +4454,8 @@
148 self.assertRaises(NoStoreError, foo2.bars.remove, object())
149
150 def test_string_reference(self):
151- class Base(object):
152- __metaclass__ = PropertyPublisherMeta
153+ class Base(six.with_metaclass(PropertyPublisherMeta, object)):
154+ pass
155
156 class MyBar(Base):
157 __storm_table__ = "bar"
158@@ -4481,8 +4481,8 @@
159 metaclass. This makes it possible to work around problems with
160 circular dependencies by delaying property resolution.
161 """
162- class Base(object):
163- __metaclass__ = PropertyPublisherMeta
164+ class Base(six.with_metaclass(PropertyPublisherMeta, object)):
165+ pass
166
167 class MyFoo(Base):
168 __storm_table__ = "foo"
169@@ -4521,8 +4521,8 @@
170 metaclass. This makes it possible to work around problems with
171 circular dependencies by delaying resolution of the order by column.
172 """
173- class Base(object):
174- __metaclass__ = PropertyPublisherMeta
175+ class Base(six.with_metaclass(PropertyPublisherMeta, object)):
176+ pass
177
178 class MyFoo(Base):
179 __storm_table__ = "foo"
180@@ -5766,8 +5766,8 @@
181 self.assertEquals(foo.title, "New Title")
182
183 def get_bar_proxy_with_string(self):
184- class Base(object):
185- __metaclass__ = PropertyPublisherMeta
186+ class Base(six.with_metaclass(PropertyPublisherMeta, object)):
187+ pass
188
189 class MyBarProxy(Base):
190 __storm_table__ = "bar"

Subscribers

People subscribed via source and target branches

to status/vote changes: