diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-09 21:52:08 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-12-09 21:52:08 +0000 |
commit | 41f5f3465a444f36473593e179168841829fc1a5 (patch) | |
tree | d407a25a902972408e4f52af33436a3b3469c44a /lib/sqlalchemy/sql/util.py | |
parent | 70f55bd2cdd0bcc6d188a24f78ee124c851b368f (diff) | |
download | sqlalchemy-41f5f3465a444f36473593e179168841829fc1a5.tar.gz |
dont use names to find Annotated subclasses
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 1bd4dd857..547753b28 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -141,9 +141,12 @@ class Annotated(object): return object.__new__(cls) else: element, values = args - # pull appropriate subclass from this module's - # namespace (see below for rationale) - cls = eval("Annotated%s" % element.__class__.__name__) + # pull appropriate subclass from registry of annotated + # classes + try: + cls = annotated_classes[element.__class__] + except KeyError: + raise KeyError("Class %s has not defined an Annotated subclass" % element.__class__) return object.__new__(cls) def __init__(self, element, values): @@ -187,13 +190,15 @@ class Annotated(object): # hard-generate Annotated subclasses. this technique # is used instead of on-the-fly types (i.e. type.__new__()) # so that the resulting objects are pickleable. +annotated_classes = {} + from sqlalchemy.sql import expression for cls in expression.__dict__.values() + [schema.Column, schema.Table]: if isinstance(cls, type) and issubclass(cls, expression.ClauseElement): exec "class Annotated%s(Annotated, cls):\n" \ " __visit_name__ = cls.__visit_name__\n"\ " pass" % (cls.__name__, ) in locals() - + exec "annotated_classes[cls] = Annotated%s" % (cls.__name__) def _deep_annotate(element, annotations, exclude=None): """Deep copy the given ClauseElement, annotating each element with the given annotations dictionary. |