From c04870ba7b8098c7d408ad66f60efe7229496fde Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 7 Mar 2017 12:53:00 -0500 Subject: Allow SchemaType and Variant to work together Added support for the :class:`.Variant` and the :class:`.SchemaType` objects to be compatible with each other. That is, a variant can be created against a type like :class:`.Enum`, and the instructions to create constraints and/or database-specific type objects will propagate correctly as per the variant's dialect mapping. Also added testing for some potential double-event scenarios on TypeDecorator but it seems usually this doesn't occur. Change-Id: I4a7e7c26b4133cd14e870f5bc34a1b2f0f19a14a Fixes: #2892 --- lib/sqlalchemy/util/langhelpers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/util') diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 973de426c..68c0f885b 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -529,20 +529,24 @@ class portable_instancemethod(object): """ - __slots__ = 'target', 'name', '__weakref__' + __slots__ = 'target', 'name', 'kwargs', '__weakref__' def __getstate__(self): - return {'target': self.target, 'name': self.name} + return {'target': self.target, 'name': self.name, + 'kwargs': self.kwargs} def __setstate__(self, state): self.target = state['target'] self.name = state['name'] + self.kwargs = state.get('kwargs', ()) - def __init__(self, meth): + def __init__(self, meth, kwargs=()): self.target = meth.__self__ self.name = meth.__name__ + self.kwargs = kwargs def __call__(self, *arg, **kw): + kw.update(self.kwargs) return getattr(self.target, self.name)(*arg, **kw) -- cgit v1.2.1