summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-12-18 17:57:15 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-12-18 17:57:15 +0000
commitbe5d3263436b81fb179c8189f1064d477d5fb3e6 (patch)
tree7f99d53445ef85d4bce4fcf6b5e244779cbcde1c /lib/sqlalchemy/sql
parent98d7d70674b443d1691971926af1b1db4d7101dc (diff)
downloadsqlalchemy-be5d3263436b81fb179c8189f1064d477d5fb3e6.tar.gz
merged -r5299:5438 of py3k warnings branch. this fixes some sqlite py2.6 testing issues,
and also addresses a significant chunk of py3k deprecations. It's mainly expicit __hash__ methods. Additionally, most usage of sets/dicts to store columns uses util-based placeholder names.
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py13
-rw-r--r--lib/sqlalchemy/sql/expression.py20
-rw-r--r--lib/sqlalchemy/sql/util.py17
-rw-r--r--lib/sqlalchemy/sql/visitors.py6
4 files changed, 31 insertions, 25 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 747978e76..921d932d2 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -162,7 +162,7 @@ class DefaultCompiler(engine.Compiled):
# a dictionary of _BindParamClause instances to "compiled" names that are
# actually present in the generated SQL
- self.bind_names = {}
+ self.bind_names = util.column_dict()
# stack which keeps track of nested SELECT statements
self.stack = []
@@ -205,6 +205,7 @@ class DefaultCompiler(engine.Compiled):
"""return a dictionary of bind parameter keys and values"""
if params:
+ params = util.column_dict(params)
pd = {}
for bindparam, name in self.bind_names.iteritems():
for paramname in (bindparam, bindparam.key, bindparam.shortname, name):
@@ -212,7 +213,7 @@ class DefaultCompiler(engine.Compiled):
pd[name] = params[paramname]
break
else:
- if callable(bindparam.value):
+ if util.callable(bindparam.value):
pd[name] = bindparam.value()
else:
pd[name] = bindparam.value
@@ -220,7 +221,7 @@ class DefaultCompiler(engine.Compiled):
else:
pd = {}
for bindparam in self.bind_names:
- if callable(bindparam.value):
+ if util.callable(bindparam.value):
pd[self.bind_names[bindparam]] = bindparam.value()
else:
pd[self.bind_names[bindparam]] = bindparam.value
@@ -317,7 +318,7 @@ class DefaultCompiler(engine.Compiled):
sep = clauselist.operator
if sep is None:
sep = " "
- elif sep == operators.comma_op:
+ elif sep is operators.comma_op:
sep = ', '
else:
sep = " " + self.operator_string(clauselist.operator) + " "
@@ -336,7 +337,7 @@ class DefaultCompiler(engine.Compiled):
name = self.function_string(func)
- if callable(name):
+ if util.callable(name):
return name(*[self.process(x) for x in func.clauses])
else:
return ".".join(func.packagenames + [name]) % {'expr':self.function_argspec(func)}
@@ -377,7 +378,7 @@ class DefaultCompiler(engine.Compiled):
def visit_binary(self, binary, **kwargs):
op = self.operator_string(binary.operator)
- if callable(op):
+ if util.callable(op):
return op(self.process(binary.left), self.process(binary.right), **binary.modifiers)
else:
return self.process(binary.left) + " " + op + " " + self.process(binary.right)
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 0f7f62e74..a4ff72b1a 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -997,7 +997,7 @@ class ClauseElement(Visitable):
of transformative operations.
"""
- s = set()
+ s = util.column_set()
f = self
while f is not None:
s.add(f)
@@ -1258,6 +1258,8 @@ class ColumnOperators(Operators):
def __le__(self, other):
return self.operate(operators.le, other)
+ __hash__ = Operators.__hash__
+
def __eq__(self, other):
return self.operate(operators.eq, other)
@@ -1580,12 +1582,12 @@ class ColumnElement(ClauseElement, _CompareMixin):
@util.memoized_property
def base_columns(self):
- return set(c for c in self.proxy_set
+ return util.column_set(c for c in self.proxy_set
if not hasattr(c, 'proxies'))
@util.memoized_property
def proxy_set(self):
- s = set([self])
+ s = util.column_set([self])
if hasattr(self, 'proxies'):
for c in self.proxies:
s.update(c.proxy_set)
@@ -1694,6 +1696,8 @@ class ColumnCollection(util.OrderedProperties):
for c in iter:
self.add(c)
+ __hash__ = None
+
def __eq__(self, other):
l = []
for c in other:
@@ -1711,9 +1715,9 @@ class ColumnCollection(util.OrderedProperties):
# have to use a Set here, because it will compare the identity
# of the column, not just using "==" for comparison which will always return a
# "True" value (i.e. a BinaryClause...)
- return col in set(self)
+ return col in util.column_set(self)
-class ColumnSet(util.OrderedSet):
+class ColumnSet(util.ordered_column_set):
def contains_column(self, col):
return col in self
@@ -1733,7 +1737,7 @@ class ColumnSet(util.OrderedSet):
return and_(*l)
def __hash__(self):
- return hash(tuple(self._list))
+ return hash(tuple(x for x in self))
class Selectable(ClauseElement):
"""mark a class as being selectable"""
@@ -1985,7 +1989,7 @@ class _BindParamClause(ColumnElement):
d = self.__dict__.copy()
v = self.value
- if callable(v):
+ if util.callable(v):
v = v()
d['value'] = v
return d
@@ -2369,7 +2373,7 @@ class _BinaryExpression(ColumnElement):
def self_group(self, against=None):
# use small/large defaults for comparison so that unknown
# operators are always parenthesized
- if self.operator != against and operators.is_precedent(self.operator, against):
+ if self.operator is not against and operators.is_precedent(self.operator, against):
return _Grouping(self)
else:
return self
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 9b9b9ec09..d0ca0b01f 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -7,6 +7,7 @@ from itertools import chain
def sort_tables(tables):
"""sort a collection of Table objects in order of their foreign-key dependency."""
+ tables = list(tables)
tuples = []
def visit_foreign_key(fkey):
if fkey.use_alter:
@@ -60,7 +61,7 @@ def find_tables(clause, check_columns=False, include_aliases=False, include_join
def find_columns(clause):
"""locate Column objects within the given expression."""
- cols = set()
+ cols = util.column_set()
def visit_column(col):
cols.add(col)
visitors.traverse(clause, {}, {'column':visit_column})
@@ -182,7 +183,7 @@ class Annotated(object):
# to this object's __dict__.
clone.__dict__.update(self.__dict__)
return Annotated(clone, self._annotations)
-
+
def __hash__(self):
return hash(self.__element)
@@ -279,9 +280,9 @@ def reduce_columns(columns, *clauses, **kw):
"""
ignore_nonexistent_tables = kw.pop('ignore_nonexistent_tables', False)
- columns = util.OrderedSet(columns)
+ columns = util.column_set(columns)
- omit = set()
+ omit = util.column_set()
for col in columns:
for fk in col.foreign_keys:
for c in columns:
@@ -301,7 +302,7 @@ def reduce_columns(columns, *clauses, **kw):
if clauses:
def visit_binary(binary):
if binary.operator == operators.eq:
- cols = set(chain(*[c.proxy_set for c in columns.difference(omit)]))
+ cols = util.column_set(chain(*[c.proxy_set for c in columns.difference(omit)]))
if binary.left in cols and binary.right in cols:
for c in columns:
if c.shares_lineage(binary.right):
@@ -444,7 +445,7 @@ class ClauseAdapter(visitors.ReplacingCloningVisitor):
self.selectable = selectable
self.include = include
self.exclude = exclude
- self.equivalents = equivalents or {}
+ self.equivalents = util.column_dict(equivalents or {})
def _corresponding_column(self, col, require_embedded, _seen=util.EMPTY_SET):
newcol = self.selectable.corresponding_column(col, require_embedded=require_embedded)
@@ -484,7 +485,7 @@ class ColumnAdapter(ClauseAdapter):
ClauseAdapter.__init__(self, selectable, equivalents, include, exclude)
if chain_to:
self.chain(chain_to)
- self.columns = util.PopulateDict(self._locate_col)
+ self.columns = util.populate_column_dict(self._locate_col)
def wrap(self, adapter):
ac = self.__class__.__new__(self.__class__)
@@ -492,7 +493,7 @@ class ColumnAdapter(ClauseAdapter):
ac._locate_col = ac._wrap(ac._locate_col, adapter._locate_col)
ac.adapt_clause = ac._wrap(ac.adapt_clause, adapter.adapt_clause)
ac.adapt_list = ac._wrap(ac.adapt_list, adapter.adapt_list)
- ac.columns = util.PopulateDict(ac._locate_col)
+ ac.columns = util.populate_column_dict(ac._locate_col)
return ac
adapt_clause = ClauseAdapter.traverse
diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py
index 17b9c59d5..a5bd497ae 100644
--- a/lib/sqlalchemy/sql/visitors.py
+++ b/lib/sqlalchemy/sql/visitors.py
@@ -207,7 +207,7 @@ def traverse_depthfirst(obj, opts, visitors):
def cloned_traverse(obj, opts, visitors):
"""clone the given expression structure, allowing modifications by visitors."""
- cloned = {}
+ cloned = util.column_dict()
def clone(element):
if element not in cloned:
@@ -234,8 +234,8 @@ def cloned_traverse(obj, opts, visitors):
def replacement_traverse(obj, opts, replace):
"""clone the given expression structure, allowing element replacement by a given replacement function."""
- cloned = {}
- stop_on = set(opts.get('stop_on', []))
+ cloned = util.column_dict()
+ stop_on = util.column_set(opts.get('stop_on', []))
def clone(element):
newelem = replace(element)