diff options
author | ijl <ijl> | 2013-06-21 00:27:50 -0400 |
---|---|---|
committer | ijl <ijl> | 2013-06-21 00:27:50 -0400 |
commit | 63a85148233bb93dff80873729f7e81bd1a1ca58 (patch) | |
tree | 6c3961d6073231d531a4ba7327c1ab833266b6e6 /lib/sqlalchemy/util/langhelpers.py | |
parent | 8c555f24b197832b9944f25d47d5989aa942bdea (diff) | |
download | sqlalchemy-pr/9.tar.gz |
types.Variant() has a __repr__ usable by Alembicpr/9
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
-rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 1ff868e01..191474576 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -342,16 +342,22 @@ def unbound_method_to_callable(func_or_cls): return func_or_cls -def generic_repr(obj, additional_kw=(), to_inspect=None): +def generic_repr(obj, to_inspect=None): """Produce a __repr__() based on direct association of the __init__() specification vs. same-named attributes present. """ - if to_inspect is None: - to_inspect = obj - missing = object() + # if a type uses **kwargs, it should give tuples of its expected + # argument names and default values in __kwargs_signature__ + additional_kw = getattr(obj, "__kwargs_signature__", ()) + if to_inspect: + if hasattr(to_inspect, "__kwargs_signature__"): + additional_kw += getattr(to_inspect, "__kwargs_signature__") + else: + to_inspect = obj + def genargs(): try: (args, vargs, vkw, defaults) = \ @@ -364,8 +370,6 @@ def generic_repr(obj, additional_kw=(), to_inspect=None): if not default_len: for arg in args[1:]: yield repr(getattr(obj, arg, None)) - if vargs is not None and hasattr(obj, vargs): - yield ', '.join(repr(val) for val in getattr(obj, vargs)) else: for arg in args[1:-default_len]: yield repr(getattr(obj, arg, None)) @@ -376,7 +380,10 @@ def generic_repr(obj, additional_kw=(), to_inspect=None): yield '%s=%r' % (arg, val) except: pass - if additional_kw: + if vargs is not None: + if hasattr(obj, vargs): + yield ', '.join(repr(val) for val in getattr(obj, vargs)) + if len(additional_kw): for arg, defval in additional_kw: try: val = getattr(obj, arg, missing) @@ -384,7 +391,7 @@ def generic_repr(obj, additional_kw=(), to_inspect=None): yield '%s=%r' % (arg, val) except: pass - + return "%s(%s)" % (obj.__class__.__name__, ", ".join(genargs())) |