launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24670
[Merge] ~cjwatson/launchpad:py3-with-metaclass into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-with-metaclass into launchpad:master.
Commit message:
Use six.with_metaclass rather than __metaclass__
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/383356
The old syntax no longer works in Python 3. See:
https://www.python.org/dev/peps/pep-3115/
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-with-metaclass into launchpad:master.
diff --git a/lib/lp/app/widgets/tests/test_popup.py b/lib/lp/app/widgets/tests/test_popup.py
index ad6f7ed..346e7d7 100644
--- a/lib/lp/app/widgets/tests/test_popup.py
+++ b/lib/lp/app/widgets/tests/test_popup.py
@@ -4,6 +4,7 @@
__metaclass__ = type
import simplejson
+import six
from zope.interface import Interface
from zope.interface.interface import InterfaceClass
from zope.schema import Choice
@@ -34,9 +35,9 @@ class TestMetaClass(InterfaceClass):
__module__=__module__)
-class ITest(Interface):
-# The schema class for the widget we will test.
- __metaclass__ = TestMetaClass
+class ITest(six.with_metaclass(TestMetaClass, Interface)):
+ # The schema class for the widget we will test.
+ pass
class TestVocabularyPickerWidget(TestCaseWithFactory):
diff --git a/lib/lp/bugs/model/apportjob.py b/lib/lp/bugs/model/apportjob.py
index c91c6ec..b99e3eb 100644
--- a/lib/lp/bugs/model/apportjob.py
+++ b/lib/lp/bugs/model/apportjob.py
@@ -114,9 +114,9 @@ class ApportJob(StormBase):
@delegate_to(IApportJob)
@provider(IApportJobSource)
-class ApportJobDerived(BaseRunnableJob):
+class ApportJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Intermediate class for deriving from ApportJob."""
- __metaclass__ = EnumeratedSubclass
def __init__(self, job):
self.context = job
diff --git a/lib/lp/code/model/branchjob.py b/lib/lp/code/model/branchjob.py
index 01a1f66..a26c47b 100644
--- a/lib/lp/code/model/branchjob.py
+++ b/lib/lp/code/model/branchjob.py
@@ -38,6 +38,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.exceptions import LostObjectError
from storm.expr import (
And,
@@ -241,9 +242,8 @@ class BranchJob(StormBase):
@delegate_to(IBranchJob)
-class BranchJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class BranchJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, branch_job):
self.context = branch_job
diff --git a/lib/lp/code/model/branchmergeproposaljob.py b/lib/lp/code/model/branchmergeproposaljob.py
index bd9fbef..d657f34 100644
--- a/lib/lp/code/model/branchmergeproposaljob.py
+++ b/lib/lp/code/model/branchmergeproposaljob.py
@@ -225,11 +225,10 @@ class BranchMergeProposalJob(StormBase):
@delegate_to(IBranchMergeProposalJob)
-class BranchMergeProposalJobDerived(BaseRunnableJob):
+class BranchMergeProposalJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Intermediate class for deriving from BranchMergeProposalJob."""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
diff --git a/lib/lp/code/model/gitjob.py b/lib/lp/code/model/gitjob.py
index fc11a40..3c041da 100644
--- a/lib/lp/code/model/gitjob.py
+++ b/lib/lp/code/model/gitjob.py
@@ -17,6 +17,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.exceptions import LostObjectError
from storm.locals import (
Int,
@@ -140,9 +141,7 @@ class GitJob(StormBase):
@delegate_to(IGitJob)
-class GitJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class GitJobDerived(six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, git_job):
self.context = git_job
diff --git a/lib/lp/oci/model/ocirecipebuildjob.py b/lib/lp/oci/model/ocirecipebuildjob.py
index c17ecf3..bd34c19 100644
--- a/lib/lp/oci/model/ocirecipebuildjob.py
+++ b/lib/lp/oci/model/ocirecipebuildjob.py
@@ -18,6 +18,7 @@ from lazr.enum import (
DBItem,
)
from lazr.lifecycle.event import ObjectCreatedEvent
+import six
from storm.databases.postgres import JSON
from storm.locals import (
Int,
@@ -98,9 +99,8 @@ class OCIRecipeBuildJob(StormBase):
@delegate_to(IOCIRecipeBuildJob)
-class OCIRecipeBuildJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class OCIRecipeBuildJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, oci_build_job):
self.context = oci_build_job
diff --git a/lib/lp/oci/model/ocirecipejob.py b/lib/lp/oci/model/ocirecipejob.py
index 529d7c1..7e18485 100644
--- a/lib/lp/oci/model/ocirecipejob.py
+++ b/lib/lp/oci/model/ocirecipejob.py
@@ -14,6 +14,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.databases.postgres import JSON
from storm.properties import Int
from storm.references import Reference
@@ -98,9 +99,8 @@ class OCIRecipeJob(StormBase):
@delegate_to(IOCIRecipeJob)
-class OCIRecipeJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class OCIRecipeJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, recipe_job):
self.context = recipe_job
diff --git a/lib/lp/registry/model/persontransferjob.py b/lib/lp/registry/model/persontransferjob.py
index 426adf1..60ec767 100644
--- a/lib/lp/registry/model/persontransferjob.py
+++ b/lib/lp/registry/model/persontransferjob.py
@@ -130,7 +130,8 @@ class PersonTransferJob(StormBase):
@delegate_to(IPersonTransferJob)
@provider(IPersonTransferJobSource)
-class PersonTransferJobDerived(BaseRunnableJob):
+class PersonTransferJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Intermediate class for deriving from PersonTransferJob.
Storm classes can't simply be subclassed or you can end up with
@@ -140,8 +141,6 @@ class PersonTransferJobDerived(BaseRunnableJob):
the run() method.
"""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
diff --git a/lib/lp/registry/model/sharingjob.py b/lib/lp/registry/model/sharingjob.py
index 9d2c444..cc2c22e 100644
--- a/lib/lp/registry/model/sharingjob.py
+++ b/lib/lp/registry/model/sharingjob.py
@@ -172,11 +172,10 @@ class SharingJob(StormBase):
@delegate_to(ISharingJob)
@provider(ISharingJobSource)
-class SharingJobDerived(BaseRunnableJob):
+class SharingJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Intermediate class for deriving from SharingJob."""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
diff --git a/lib/lp/services/tests/test_utils.py b/lib/lp/services/tests/test_utils.py
index 02922bb..333a612 100644
--- a/lib/lp/services/tests/test_utils.py
+++ b/lib/lp/services/tests/test_utils.py
@@ -15,6 +15,7 @@ import sys
from fixtures import TempDir
from pytz import UTC
+import six
from testtools.matchers import (
Equals,
GreaterThan,
@@ -68,8 +69,9 @@ class TestAutoDecorate(TestCase):
def test_auto_decorate(self):
# All of the decorators passed to AutoDecorate are applied as
# decorators in reverse order.
- class AutoDecoratedClass:
- __metaclass__ = AutoDecorate(self.decorator_1, self.decorator_2)
+ class AutoDecoratedClass(
+ six.with_metaclass(
+ AutoDecorate(self.decorator_1, self.decorator_2), object)):
def method_a(s):
self.log.append('a')
diff --git a/lib/lp/services/webhooks/model.py b/lib/lp/services/webhooks/model.py
index cb42ce9..e60975f 100644
--- a/lib/lp/services/webhooks/model.py
+++ b/lib/lp/services/webhooks/model.py
@@ -368,9 +368,8 @@ class WebhookJob(StormBase):
@delegate_to(IWebhookJob)
-class WebhookJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class WebhookJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, webhook_job):
self.context = webhook_job
diff --git a/lib/lp/snappy/model/snapbuildjob.py b/lib/lp/snappy/model/snapbuildjob.py
index 3002777..298c00f 100644
--- a/lib/lp/snappy/model/snapbuildjob.py
+++ b/lib/lp/snappy/model/snapbuildjob.py
@@ -20,6 +20,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.locals import (
Int,
JSON,
@@ -115,9 +116,8 @@ class SnapBuildJob(StormBase):
@delegate_to(ISnapBuildJob)
-class SnapBuildJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class SnapBuildJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, snap_build_job):
self.context = snap_build_job
diff --git a/lib/lp/snappy/model/snapjob.py b/lib/lp/snappy/model/snapjob.py
index 367450f..5b1f08d 100644
--- a/lib/lp/snappy/model/snapjob.py
+++ b/lib/lp/snappy/model/snapjob.py
@@ -19,6 +19,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.locals import (
Desc,
Int,
@@ -120,9 +121,7 @@ class SnapJob(StormBase):
@delegate_to(ISnapJob)
-class SnapJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class SnapJobDerived(six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
def __init__(self, snap_job):
self.context = snap_job
diff --git a/lib/lp/soyuz/model/archivejob.py b/lib/lp/soyuz/model/archivejob.py
index 12b8659..b691683 100644
--- a/lib/lp/soyuz/model/archivejob.py
+++ b/lib/lp/soyuz/model/archivejob.py
@@ -7,6 +7,7 @@ import logging
import StringIO
from lazr.delegates import delegate_to
+import six
from storm.expr import And
from storm.locals import (
Int,
@@ -77,11 +78,10 @@ class ArchiveJob(StormBase):
@delegate_to(IArchiveJob)
@provider(IArchiveJobSource)
-class ArchiveJobDerived(BaseRunnableJob):
+class ArchiveJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Intermediate class for deriving from ArchiveJob."""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
diff --git a/lib/lp/soyuz/model/distributionjob.py b/lib/lp/soyuz/model/distributionjob.py
index 87bbb6a..57feaf6 100644
--- a/lib/lp/soyuz/model/distributionjob.py
+++ b/lib/lp/soyuz/model/distributionjob.py
@@ -9,6 +9,7 @@ __all__ = [
]
from lazr.delegates import delegate_to
+import six
from storm.locals import (
And,
Int,
@@ -68,11 +69,10 @@ class DistributionJob(StormBase):
@delegate_to(IDistributionJob)
-class DistributionJobDerived(BaseRunnableJob):
+class DistributionJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Abstract class for deriving from DistributionJob."""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
diff --git a/lib/lp/soyuz/model/packagecopyjob.py b/lib/lp/soyuz/model/packagecopyjob.py
index a7f41fd..b4d92b2 100644
--- a/lib/lp/soyuz/model/packagecopyjob.py
+++ b/lib/lp/soyuz/model/packagecopyjob.py
@@ -13,6 +13,7 @@ import logging
from lazr.delegates import delegate_to
from lazr.jobrunner.jobrunner import SuspendJobException
from psycopg2.extensions import TransactionRollbackError
+import six
from storm.locals import (
Int,
JSON,
@@ -175,11 +176,10 @@ class PackageCopyJob(StormBase):
@delegate_to(IPackageCopyJob)
-class PackageCopyJobDerived(BaseRunnableJob):
+class PackageCopyJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
"""Abstract class for deriving from PackageCopyJob."""
- __metaclass__ = EnumeratedSubclass
-
def __init__(self, job):
self.context = job
self.logger = logging.getLogger()
diff --git a/lib/lp/soyuz/model/packagediffjob.py b/lib/lp/soyuz/model/packagediffjob.py
index 508143e..9f9cb3d 100644
--- a/lib/lp/soyuz/model/packagediffjob.py
+++ b/lib/lp/soyuz/model/packagediffjob.py
@@ -9,6 +9,7 @@ __all__ = [
from lazr.delegates import delegate_to
import simplejson
+import six
from zope.component import getUtility
from zope.interface import (
implementer,
@@ -32,9 +33,8 @@ from lp.soyuz.interfaces.packagediffjob import (
@delegate_to(IPackageDiffJob)
@provider(IPackageDiffJobSource)
-class PackageDiffJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class PackageDiffJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
config = config.IPackageDiffJobSource
diff --git a/lib/lp/soyuz/model/packagetranslationsuploadjob.py b/lib/lp/soyuz/model/packagetranslationsuploadjob.py
index 96134b5..0af6707 100644
--- a/lib/lp/soyuz/model/packagetranslationsuploadjob.py
+++ b/lib/lp/soyuz/model/packagetranslationsuploadjob.py
@@ -13,6 +13,7 @@ import os
import tempfile
from lazr.delegates import delegate_to
+import six
from zope.component import getUtility
from zope.interface import (
implementer,
@@ -75,9 +76,8 @@ def _filter_ubuntu_translation_file(filename):
@delegate_to(IPackageTranslationsUploadJob)
@provider(IPackageTranslationsUploadJobSource)
-class PackageTranslationsUploadJobDerived(BaseRunnableJob):
-
- __metaclass__ = EnumeratedSubclass
+class PackageTranslationsUploadJobDerived(
+ six.with_metaclass(EnumeratedSubclass, BaseRunnableJob)):
config = config.IPackageTranslationsUploadJobSource
diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
index 70c8a01..815ad8f 100644
--- a/lib/lp/testing/factory.py
+++ b/lib/lp/testing/factory.py
@@ -429,11 +429,10 @@ class GPGSigningContext:
self.mode = mode
-class ObjectFactory:
+class ObjectFactory(
+ six.with_metaclass(AutoDecorate(default_master_store)), object):
"""Factory methods for creating basic Python objects."""
- __metaclass__ = AutoDecorate(default_master_store)
-
# This allocates process-wide unique integers. We count on Python doing
# only cooperative threading to make this safe across threads.
_unique_int_counter = count(100000)
diff --git a/lib/lp/translations/model/translationsharingjob.py b/lib/lp/translations/model/translationsharingjob.py
index 80cdad4..8a60008 100644
--- a/lib/lp/translations/model/translationsharingjob.py
+++ b/lib/lp/translations/model/translationsharingjob.py
@@ -16,6 +16,7 @@ from lazr.enum import (
DBEnumeratedType,
DBItem,
)
+import six
from storm.locals import (
Int,
Reference,
@@ -114,11 +115,10 @@ class TranslationSharingJob(StormBase):
@delegate_to(ITranslationSharingJob)
-class TranslationSharingJobDerived:
+class TranslationSharingJobDerived(
+ six.with_metaclass(EnumeratedSubclass, object)):
"""Base class for specialized TranslationTemplate Job types."""
- __metaclass__ = EnumeratedSubclass
-
def getDBClass(self):
return TranslationSharingJob