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
=== modified file 'storm/base.py'
--- storm/base.py 2019-06-05 11:41:07 +0000
+++ storm/base.py 2019-08-11 09:00:12 +0000
@@ -20,18 +20,19 @@
20#20#
21from __future__ import print_function21from __future__ import print_function
2222
23import six
24
23from storm.properties import PropertyPublisherMeta25from storm.properties import PropertyPublisherMeta
2426
2527
26__all__ = ["Storm"]28__all__ = ["Storm"]
2729
2830
29class Storm(object):31class Storm(six.with_metaclass(PropertyPublisherMeta, object)):
30 """An optional base class for objects stored in a Storm Store.32 """An optional base class for objects stored in a Storm Store.
3133
32 It causes your subclasses to be associated with a Storm34 It causes your subclasses to be associated with a Storm
33 PropertyRegistry. It is necessary to use this if you want to35 PropertyRegistry. It is necessary to use this if you want to
34 specify References with strings.36 specify References with strings.
35 """37 """
36 __metaclass__ = PropertyPublisherMeta
3738
3839
=== modified file 'storm/sqlobject.py'
--- storm/sqlobject.py 2019-06-05 11:41:07 +0000
+++ storm/sqlobject.py 2019-08-11 09:00:12 +0000
@@ -28,6 +28,8 @@
28import re28import re
29import warnings29import warnings
3030
31import six
32
31from storm.properties import (33from storm.properties import (
32 RawStr, Int, Bool, Float, DateTime, Date, TimeDelta)34 RawStr, Int, Bool, Float, DateTime, Date, TimeDelta)
33from storm.references import Reference, ReferenceSet35from storm.references import Reference, ReferenceSet
@@ -261,7 +263,7 @@
261 return getattr(self._cls, attr)263 return getattr(self._cls, attr)
262264
263265
264class SQLObjectBase(Storm):266class SQLObjectBase(six.with_metaclass(SQLObjectMeta, Storm)):
265 """The root class of all SQLObject-emulating classes in your application.267 """The root class of all SQLObject-emulating classes in your application.
266268
267 The general strategy for using Storm's SQLObject emulation layer269 The general strategy for using Storm's SQLObject emulation layer
@@ -271,7 +273,6 @@
271 even be implemented as returning a global L{Store} instance. Then273 even be implemented as returning a global L{Store} instance. Then
272 all database classes should subclass that class.274 all database classes should subclass that class.
273 """275 """
274 __metaclass__ = SQLObjectMeta
275276
276 q = DotQ()277 q = DotQ()
277 _SO_creating = False278 _SO_creating = False
278279
=== modified file 'tests/info.py'
--- tests/info.py 2019-06-05 11:41:07 +0000
+++ tests/info.py 2019-08-11 09:00:12 +0000
@@ -23,6 +23,8 @@
23from weakref import ref23from weakref import ref
24import gc24import gc
2525
26import six
27
26from storm.exceptions import ClassInfoError28from storm.exceptions import ClassInfoError
27from storm.properties import Property29from storm.properties import Property
28from storm.variables import Variable30from storm.variables import Variable
@@ -571,8 +573,7 @@
571 cls = type.__new__(meta_cls, name, bases, dict)573 cls = type.__new__(meta_cls, name, bases, dict)
572 cls.__storm_table__ = "HAH! GOTCH YA!"574 cls.__storm_table__ = "HAH! GOTCH YA!"
573 return cls575 return cls
574 class Class(object):576 class Class(six.with_metaclass(MetaClass, object)):
575 __metaclass__ = MetaClass
576 __storm_table__ = "table"577 __storm_table__ = "table"
577 prop1 = Property("column1", primary=True)578 prop1 = Property("column1", primary=True)
578 Alias = ClassAlias(Class, "USE_THIS")579 Alias = ClassAlias(Class, "USE_THIS")
579580
=== modified file 'tests/mocker.py'
--- tests/mocker.py 2019-06-07 17:14:33 +0000
+++ tests/mocker.py 2019-08-11 09:00:12 +0000
@@ -13,6 +13,7 @@
13import os13import os
14import gc14import gc
1515
16import six
16from six.moves import builtins17from six.moves import builtins
1718
1819
@@ -324,7 +325,14 @@
324 return bound_method325 return bound_method
325326
326327
327class MockerBase(object):328class MockerMeta(type):
329
330 def __init__(self, name, bases, dict):
331 # Make independent lists on each subclass, inheriting from parent.
332 self._recorders = list(getattr(self, "_recorders", ()))
333
334
335class MockerBase(six.with_metaclass(MockerMeta, object)):
328 """Controller of mock objects.336 """Controller of mock objects.
329337
330 A mocker instance is used to command recording and replay of338 A mocker instance is used to command recording and replay of
@@ -380,11 +388,6 @@
380 # For convenience only.388 # For convenience only.
381 on = expect389 on = expect
382390
383 class __metaclass__(type):
384 def __init__(self, name, bases, dict):
385 # Make independent lists on each subclass, inheriting from parent.
386 self._recorders = list(getattr(self, "_recorders", ()))
387
388 def __init__(self):391 def __init__(self):
389 self._recorders = self._recorders[:]392 self._recorders = self._recorders[:]
390 self._events = []393 self._events = []
391394
=== modified file 'tests/properties.py'
--- tests/properties.py 2019-06-05 11:41:07 +0000
+++ tests/properties.py 2019-08-11 09:00:12 +0000
@@ -25,6 +25,8 @@
25import gc25import gc
26import uuid26import uuid
2727
28import six
29
28from storm.compat import json30from storm.compat import json
29from storm.exceptions import NoneError, PropertyPathError31from storm.exceptions import NoneError, PropertyPathError
30from storm.properties import PropertyPublisherMeta32from storm.properties import PropertyPublisherMeta
@@ -986,8 +988,8 @@
986 def setUp(self):988 def setUp(self):
987 TestHelper.setUp(self)989 TestHelper.setUp(self)
988990
989 class Base(object):991 class Base(six.with_metaclass(PropertyPublisherMeta, object)):
990 __metaclass__ = PropertyPublisherMeta992 pass
991993
992 class Class(Base):994 class Class(Base):
993 __storm_table__ = "mytable"995 __storm_table__ = "mytable"
994996
=== modified file 'tests/store/base.py'
--- tests/store/base.py 2019-06-07 17:14:33 +0000
+++ tests/store/base.py 2019-08-11 09:00:12 +0000
@@ -4454,8 +4454,8 @@
4454 self.assertRaises(NoStoreError, foo2.bars.remove, object())4454 self.assertRaises(NoStoreError, foo2.bars.remove, object())
44554455
4456 def test_string_reference(self):4456 def test_string_reference(self):
4457 class Base(object):4457 class Base(six.with_metaclass(PropertyPublisherMeta, object)):
4458 __metaclass__ = PropertyPublisherMeta4458 pass
44594459
4460 class MyBar(Base):4460 class MyBar(Base):
4461 __storm_table__ = "bar"4461 __storm_table__ = "bar"
@@ -4481,8 +4481,8 @@
4481 metaclass. This makes it possible to work around problems with4481 metaclass. This makes it possible to work around problems with
4482 circular dependencies by delaying property resolution.4482 circular dependencies by delaying property resolution.
4483 """4483 """
4484 class Base(object):4484 class Base(six.with_metaclass(PropertyPublisherMeta, object)):
4485 __metaclass__ = PropertyPublisherMeta4485 pass
44864486
4487 class MyFoo(Base):4487 class MyFoo(Base):
4488 __storm_table__ = "foo"4488 __storm_table__ = "foo"
@@ -4521,8 +4521,8 @@
4521 metaclass. This makes it possible to work around problems with4521 metaclass. This makes it possible to work around problems with
4522 circular dependencies by delaying resolution of the order by column.4522 circular dependencies by delaying resolution of the order by column.
4523 """4523 """
4524 class Base(object):4524 class Base(six.with_metaclass(PropertyPublisherMeta, object)):
4525 __metaclass__ = PropertyPublisherMeta4525 pass
45264526
4527 class MyFoo(Base):4527 class MyFoo(Base):
4528 __storm_table__ = "foo"4528 __storm_table__ = "foo"
@@ -5766,8 +5766,8 @@
5766 self.assertEquals(foo.title, "New Title")5766 self.assertEquals(foo.title, "New Title")
57675767
5768 def get_bar_proxy_with_string(self):5768 def get_bar_proxy_with_string(self):
5769 class Base(object):5769 class Base(six.with_metaclass(PropertyPublisherMeta, object)):
5770 __metaclass__ = PropertyPublisherMeta5770 pass
57715771
5772 class MyBarProxy(Base):5772 class MyBarProxy(Base):
5773 __storm_table__ = "bar"5773 __storm_table__ = "bar"

Subscribers

People subscribed via source and target branches

to status/vote changes: