diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/event.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 15 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/visitors.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/util/compat.py | 19 |
4 files changed, 26 insertions, 13 deletions
diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index d8c44dd05..bfd027ead 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -171,8 +171,7 @@ class _EventMeta(type): associated _Dispatch classes.""" def __init__(cls, classname, bases, dict_): - if classname != 'MetaBase': - _create_dispatcher_class(cls, classname, bases, dict_) + _create_dispatcher_class(cls, classname, bases, dict_) return type.__init__(cls, classname, bases, dict_) diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 244505bed..5e2d0792c 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -31,14 +31,13 @@ def register_function(identifier, fn, package="_default"): class _GenericMeta(VisitableType): def __init__(cls, clsname, bases, clsdict): - if clsname != 'MetaBase': - cls.name = name = clsdict.get('name', clsname) - cls.identifier = identifier = clsdict.get('identifier', name) - package = clsdict.pop('package', '_default') - # legacy - if '__return_type__' in clsdict: - cls.type = clsdict['__return_type__'] - register_function(identifier, cls, package) + cls.name = name = clsdict.get('name', clsname) + cls.identifier = identifier = clsdict.get('identifier', name) + package = clsdict.pop('package', '_default') + # legacy + if '__return_type__' in clsdict: + cls.type = clsdict['__return_type__'] + register_function(identifier, cls, package) super(_GenericMeta, cls).__init__(clsname, bases, clsdict) diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 4d2948462..62f46ab64 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -49,7 +49,7 @@ class VisitableType(type): Classes having no __visit_name__ attribute will remain unaffected. """ def __init__(cls, clsname, bases, clsdict): - if clsname not in ('MetaBase', 'Visitable') and \ + if clsname != 'Visitable' and \ hasattr(cls, '__visit_name__'): _generate_dispatch(cls) diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 3bbce5dde..fea22873c 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -209,6 +209,21 @@ else: def with_metaclass(meta, *bases): - """Create a base class with a metaclass.""" + """Create a base class with a metaclass. + + Drops the middle class upon creation. + + Source: http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ + + """ + + class metaclass(meta): + __call__ = type.__call__ + __init__ = type.__init__ + def __new__(cls, name, this_bases, d): + if this_bases is None: + return type.__new__(cls, name, (), d) + return meta(name, bases, d) + return metaclass('temporary_class', None, {}) + - return meta("MetaBase", bases, {}) |