Skip to content

Commit 05877de

Browse files
committed
qcore: Add __prepare__ to some meta classes
Classes passed to `six.with_metaclass()` are expected to have a `__prepare__` method to pass `tox` checks, which is not defined by default in PY2 and not used. See also <benjaminp/six#252>.
1 parent 203127b commit 05877de

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ __pycache__/
1313
.arcconfig
1414
.tox/
1515
.mypy_cache/
16+
build/

qcore/disallow_inheritance.py

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ def __init__(self, cl_name, bases, namespace):
2828
(cls, cl_name)
2929
raise TypeError(message)
3030
super(DisallowInheritance, self).__init__(cl_name, bases, namespace)
31+
32+
# Needed bcz of a six bug: https://github.com/benjaminp/six/issues/252
33+
@classmethod
34+
def __prepare__(cls, name, bases, **kwargs):
35+
return {}
36+

qcore/enum.py

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def _make_value(self, value):
9090
member.__init__(value)
9191
return member
9292

93+
# Needed bcz of a six bug: https://github.com/benjaminp/six/issues/252
94+
@classmethod
95+
def __prepare__(cls, name, bases, **kwargs):
96+
return {}
97+
9398

9499
class EnumBase(six.with_metaclass(EnumType)):
95100
_name_to_member = {}

qcore/events.py

+10
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ def __repr__(self):
322322
"""Gets the ``repr`` representation of this object."""
323323
return '%s(%r)' % (self.__class__.__name__, self.__dict__)
324324

325+
# Needed bcz of a six bug: https://github.com/benjaminp/six/issues/252
326+
@classmethod
327+
def __prepare__(cls, name, bases, **kwargs):
328+
return {}
329+
325330

326331
class EnumBasedEventHubType(type):
327332
"""Metaclass for enum-based event hubs.
@@ -373,6 +378,11 @@ def __init__(cls, what, bases=None, dict=None):
373378
# similar instance members
374379
delattr(cls, 'on_' + name)
375380

381+
# Needed bcz of a six bug: https://github.com/benjaminp/six/issues/252
382+
@classmethod
383+
def __prepare__(cls, name, bases, **kwargs):
384+
return {}
385+
376386

377387
class EnumBasedEventHub(six.with_metaclass(EnumBasedEventHubType, EventHub)):
378388
__based_on__ = []

0 commit comments

Comments
 (0)