Fixed compatibility in Python2
This commit is contained in:
parent
88bb892ae1
commit
8eccbe5293
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
pint.compat.meta
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Compatibility layer.
|
||||
|
||||
:copyright: 2016 by Pint Authors, see AUTHORS for more details.
|
||||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
|
||||
def with_metaclass(meta, *bases):
|
||||
"""Create a base class with a metaclass."""
|
||||
# This requires a bit of explanation: the basic idea is to make a dummy
|
||||
# metaclass for one level of class instantiation that replaces itself with
|
||||
# the actual metaclass.
|
||||
|
||||
# Taken from six
|
||||
|
||||
class metaclass(meta):
|
||||
|
||||
def __new__(cls, name, this_bases, d):
|
||||
return meta(name, bases, d)
|
||||
return type.__new__(metaclass, 'temporary_class', (), {})
|
|
@ -51,7 +51,7 @@ from .util import (logger, pi_theorem, solve_dependencies, ParserHelper,
|
|||
find_shortest_path, UnitsContainer, _is_dim,
|
||||
to_units_container, SourceIterator)
|
||||
|
||||
from .compat import tokenizer, string_types
|
||||
from .compat import tokenizer, string_types, meta
|
||||
from .definitions import (Definition, UnitDefinition, PrefixDefinition,
|
||||
DimensionDefinition)
|
||||
from .converters import ScaleConverter
|
||||
|
@ -64,21 +64,6 @@ from . import systems
|
|||
_BLOCK_RE = re.compile(r' |\(')
|
||||
|
||||
|
||||
def _with_metaclass(meta, *bases):
|
||||
"""Create a base class with a metaclass."""
|
||||
# This requires a bit of explanation: the basic idea is to make a dummy
|
||||
# metaclass for one level of class instantiation that replaces itself with
|
||||
# the actual metaclass.
|
||||
|
||||
# Taken from six
|
||||
|
||||
class metaclass(meta):
|
||||
|
||||
def __new__(cls, name, this_bases, d):
|
||||
return meta(name, bases, d)
|
||||
return type.__new__(metaclass, 'temporary_class', (), {})
|
||||
|
||||
|
||||
class _Meta(type):
|
||||
"""This is just to call after_init at the right time
|
||||
instead of asking the developer to do it when subclassing.
|
||||
|
@ -90,7 +75,7 @@ class _Meta(type):
|
|||
return obj
|
||||
|
||||
|
||||
class BaseRegistry(_with_metaclass(_Meta)):
|
||||
class BaseRegistry(meta.with_metaclass(_Meta)):
|
||||
"""Base class for all registries.
|
||||
|
||||
Capabilities:
|
||||
|
|
Loading…
Reference in New Issue