Fix compatibility
This commit fixes usage of the Singleton metaclass so that it is compatible with both Python 2 and Python 3.
This commit is contained in:
parent
c638e25941
commit
69502854aa
2 changed files with 7 additions and 3 deletions
|
@ -1,11 +1,10 @@
|
|||
import sys
|
||||
from ..util.singleton import Singleton
|
||||
from ..util.compat import with_metaclass
|
||||
from .color import Color
|
||||
from .level import Level
|
||||
|
||||
class Messenger(object):
|
||||
__metaclass__ = Singleton
|
||||
|
||||
class Messenger(with_metaclass(Singleton, object)):
|
||||
def __init__(self, level = Level.LOWINFO):
|
||||
self.set_level(level)
|
||||
|
||||
|
|
5
dotbot/util/compat.py
Normal file
5
dotbot/util/compat.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
def with_metaclass(meta, *bases):
|
||||
class metaclass(meta):
|
||||
def __new__(cls, name, this_bases, d):
|
||||
return meta(name, bases, d)
|
||||
return type.__new__(metaclass, 'temporary_class', (), {})
|
Loading…
Reference in a new issue