[Sqlalchemy-commits] [5302] sqlalchemy/branches/py3k_warnings: straight removal of all -3 warnings
Brought to you by:
zzzeek
From: <co...@sq...> - 2008-11-17 00:31:30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[5302] sqlalchemy/branches/py3k_warnings: straight removal of all -3 warnings partially complete.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5302</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2008-11-16 19:31:23 -0500 (Sun, 16 Nov 2008)</dd> </dl> <h3>Log Message</h3> <pre>straight removal of all -3 warnings partially complete.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemyenginebasepy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/base.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemyengineurlpy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/url.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemyormpropertiespy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/orm/properties.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemyschemapy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/schema.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemysqlexpressionpy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/sql/expression.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemytypespy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/types.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningslibsqlalchemyutilpy">sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/util.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningstestbaseutilspy">sqlalchemy/branches/py3k_warnings/test/base/utils.py</a></li> <li><a href="#sqlalchemybranchespy3k_warningstesttestlibfixturespy">sqlalchemy/branches/py3k_warnings/test/testlib/fixtures.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchespy3k_warningslibsqlalchemyenginebasepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/base.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/base.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/base.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -1247,7 +1247,6 @@ </span><span class="cx"> </span><span class="cx"> return self.pool.unique_connection() </span><span class="cx"> </span><del>- </del><span class="cx"> def _proxy_connection_cls(cls, proxy): </span><span class="cx"> class ProxyConnection(cls): </span><span class="cx"> def execute(self, object, *multiparams, **params): </span><span class="lines">@@ -1299,6 +1298,8 @@ </span><span class="cx"> for i in xrange(len(self.__row)): </span><span class="cx"> yield self.__parent._get_col(self.__row, i) </span><span class="cx"> </span><ins>+ __hash__ = None + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> return ((other is self) or </span><span class="cx"> (other == tuple(self.__parent._get_col(self.__row, key) </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemyengineurlpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/url.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/url.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/engine/url.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -75,6 +75,9 @@ </span><span class="cx"> s += '?' + "&".join("%s=%s" % (k, self.query[k]) for k in keys) </span><span class="cx"> return s </span><span class="cx"> </span><ins>+ def __hash__(self): + return hash(str(self)) + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> return \ </span><span class="cx"> isinstance(other, URL) and \ </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemyormpropertiespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/orm/properties.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/orm/properties.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/orm/properties.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -156,6 +156,8 @@ </span><span class="cx"> else: </span><span class="cx"> return expression.ClauseList(*self.prop.columns) </span><span class="cx"> </span><ins>+ __hash__ = None + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> if other is None: </span><span class="cx"> values = [None] * len(self.prop.columns) </span><span class="lines">@@ -363,6 +365,8 @@ </span><span class="cx"> raise NotImplementedError("in_() not yet supported for relations. For a " </span><span class="cx"> "simple many-to-one, use in_() against the set of foreign key values.") </span><span class="cx"> </span><ins>+ __hash__ = None + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> if other is None: </span><span class="cx"> if self.prop.direction in [ONETOMANY, MANYTOMANY]: </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemyschemapy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/schema.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/schema.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/schema.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -1274,6 +1274,8 @@ </span><span class="cx"> def copy(self, **kw): </span><span class="cx"> return PrimaryKeyConstraint(name=self.name, *[c.key for c in self]) </span><span class="cx"> </span><ins>+ __hash__ = Constraint.__hash__ + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> return self.columns == other </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemysqlexpressionpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/sql/expression.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/sql/expression.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/sql/expression.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -1263,6 +1263,8 @@ </span><span class="cx"> def __le__(self, other): </span><span class="cx"> return self.operate(operators.le, other) </span><span class="cx"> </span><ins>+ __hash__ = Operators.__hash__ + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> return self.operate(operators.eq, other) </span><span class="cx"> </span><span class="lines">@@ -1578,8 +1580,6 @@ </span><span class="cx"> foreign_keys = [] </span><span class="cx"> quote = None </span><span class="cx"> </span><del>- __hash__ = None - </del><span class="cx"> @property </span><span class="cx"> def _select_iterable(self): </span><span class="cx"> return (self, ) </span><span class="lines">@@ -1700,6 +1700,8 @@ </span><span class="cx"> for c in iter: </span><span class="cx"> self.add(c) </span><span class="cx"> </span><ins>+ __hash__ = None + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> l = [] </span><span class="cx"> for c in other: </span><span class="lines">@@ -1719,7 +1721,7 @@ </span><span class="cx"> # "True" value (i.e. a BinaryClause...) </span><span class="cx"> return col in util.column_set(self) </span><span class="cx"> </span><del>-class ColumnSet(util.column_set): </del><ins>+class ColumnSet(util.ordered_column_set): </ins><span class="cx"> def contains_column(self, col): </span><span class="cx"> return col in self </span><span class="cx"> </span><span class="lines">@@ -1739,7 +1741,7 @@ </span><span class="cx"> return and_(*l) </span><span class="cx"> </span><span class="cx"> def __hash__(self): </span><del>- return hash(tuple(id(x) for x in self)) </del><ins>+ return hash(tuple(x for x in self)) </ins><span class="cx"> </span><span class="cx"> class Selectable(ClauseElement): </span><span class="cx"> """mark a class as being selectable""" </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemytypespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/types.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/types.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/types.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -284,7 +284,7 @@ </span><span class="cx"> """marks a type as supporting 'concatenation'""" </span><span class="cx"> def adapt_operator(self, op): </span><span class="cx"> from sqlalchemy.sql import operators </span><del>- if op == operators.add: </del><ins>+ if op is operators.add: </ins><span class="cx"> return operators.concat_op </span><span class="cx"> else: </span><span class="cx"> return op </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningslibsqlalchemyutilpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/util.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/util.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/lib/sqlalchemy/util.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -18,7 +18,7 @@ </span><span class="cx"> import dummy_threading as threading </span><span class="cx"> from dummy_threading import local as ThreadLocal </span><span class="cx"> </span><del>-py3k = sys.py3kwarning or sys.version_info >= (3, 0) </del><ins>+py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0) </ins><span class="cx"> </span><span class="cx"> if sys.version_info < (2, 6): </span><span class="cx"> import sets </span><span class="lines">@@ -833,10 +833,10 @@ </span><span class="cx"> </span><span class="cx"> This strategy has edge cases for builtin types- it's possible to have </span><span class="cx"> two 'foo' strings in one of these sets, for example. Use sparingly. </span><ins>+ </ins><span class="cx"> """ </span><span class="cx"> </span><span class="cx"> _working_set = set </span><del>- __hash_func__ = id </del><span class="cx"> </span><span class="cx"> def __init__(self, iterable=None): </span><span class="cx"> self._members = dict() </span><span class="lines">@@ -845,13 +845,13 @@ </span><span class="cx"> self.add(o) </span><span class="cx"> </span><span class="cx"> def add(self, value): </span><del>- self._members[self.__hash_func__(value)] = value </del><ins>+ self._members[id(value)] = value </ins><span class="cx"> </span><span class="cx"> def __contains__(self, value): </span><del>- return self.__hash_func__(value) in self._members </del><ins>+ return id(value) in self._members </ins><span class="cx"> </span><span class="cx"> def remove(self, value): </span><del>- del self._members[self.__hash_func__(value)] </del><ins>+ del self._members[id(value)] </ins><span class="cx"> </span><span class="cx"> def discard(self, value): </span><span class="cx"> try: </span><span class="lines">@@ -929,7 +929,7 @@ </span><span class="cx"> result = type(self)() </span><span class="cx"> # testlib.pragma exempt:__hash__ </span><span class="cx"> result._members.update( </span><del>- self._working_set(self._member_id_tuples()).union(_iter_id(iterable, self.__hash_func__))) </del><ins>+ self._working_set(self._member_id_tuples()).union(_iter_id(iterable))) </ins><span class="cx"> return result </span><span class="cx"> </span><span class="cx"> def __or__(self, other): </span><span class="lines">@@ -950,7 +950,7 @@ </span><span class="cx"> result = type(self)() </span><span class="cx"> # testlib.pragma exempt:__hash__ </span><span class="cx"> result._members.update( </span><del>- self._working_set(self._member_id_tuples()).difference(_iter_id(iterable, self.__hash_func__))) </del><ins>+ self._working_set(self._member_id_tuples()).difference(_iter_id(iterable))) </ins><span class="cx"> return result </span><span class="cx"> </span><span class="cx"> def __sub__(self, other): </span><span class="lines">@@ -971,7 +971,7 @@ </span><span class="cx"> result = type(self)() </span><span class="cx"> # testlib.pragma exempt:__hash__ </span><span class="cx"> result._members.update( </span><del>- self._working_set(self._member_id_tuples()).intersection(_iter_id(iterable, self.__hash_func__))) </del><ins>+ self._working_set(self._member_id_tuples()).intersection(_iter_id(iterable))) </ins><span class="cx"> return result </span><span class="cx"> </span><span class="cx"> def __and__(self, other): </span><span class="lines">@@ -992,11 +992,11 @@ </span><span class="cx"> result = type(self)() </span><span class="cx"> # testlib.pragma exempt:__hash__ </span><span class="cx"> result._members.update( </span><del>- self._working_set(self._member_id_tuples()).symmetric_difference(_iter_id(iterable, self.__hash_func__))) </del><ins>+ self._working_set(self._member_id_tuples()).symmetric_difference(_iter_id(iterable))) </ins><span class="cx"> return result </span><span class="cx"> </span><span class="cx"> def _member_id_tuples(self): </span><del>- return (_id_tuple(v, self.__hash_func__) for v in self._members.itervalues()) </del><ins>+ return ((id(v), v) for v in self._members.itervalues()) </ins><span class="cx"> </span><span class="cx"> def __xor__(self, other): </span><span class="cx"> if not isinstance(other, IdentitySet): </span><span class="lines">@@ -1029,67 +1029,7 @@ </span><span class="cx"> def __repr__(self): </span><span class="cx"> return '%s(%r)' % (type(self).__name__, self._members.values()) </span><span class="cx"> </span><del>-class IdentityDict(dict): - """A dictionary that considers only object id() for uniqueness.""" - - __hash_func__ = id - - def __init__(self, items=None): - self._keys = {} - if items: - self.update(items) - - def update(self, items): - if isinstance(items, dict): - iter_ = list(items.iteritems()) - else: - iter_ = list(items) - dict.update(self, ((self.__hash_func__(key), value) for key, value in iter_)) - self._keys.update((self.__hash_func__(key), key) for key, value in iter_) - - def __getitem__(self, key): - return dict.__getitem__(self, self.__hash_func__(key)) </del><span class="cx"> </span><del>- def __setitem__(self, key, value): - dict.__setitem__(self, self.__hash_func__(key), value) - self._keys[self.__hash_func__(key)] = key - - def setdefault(self, key, value): - r = dict.setdefault(self, self.__hash_func__(key), value) - self._keys[self.__hash_func__(key)] = key - return r - - def __delitem__(self, key): - dict.__delitem__(self, self.__hash_func__(key)) - del self._keys[self.__hash_func__(key)] - - def keys(self): - return self._keys.values() - - def __iter__(self): - return self._keys.itervalues() - - def iteritems(self): - return iter((vk, dict.__getitem__(self, idk)) for idk, vk in self._keys.iteritems()) - - def __contains__(self, key): - return dict.__contains__(self, self.__hash_func__(key)) - -class PopulateIdentityDict(IdentityDict): - def __init__(self, creator): - IdentityDict.__init__(self) - self.creator = creator - - def __getitem__(self, key): - if not dict.__contains__(self, self.__hash_func__(key)): - return self.__missing__(key) - else: - return dict.__getitem__(self, self.__hash_func__(key)) - - def __missing__(self, key): - self[key] = val = self.creator(key) - return val - </del><span class="cx"> class OrderedIdentitySet(IdentitySet): </span><span class="cx"> class _working_set(OrderedSet): </span><span class="cx"> # a testing pragma: exempt the OIDS working set from the test suite's </span><span class="lines">@@ -1105,44 +1045,18 @@ </span><span class="cx"> for o in iterable: </span><span class="cx"> self.add(o) </span><span class="cx"> </span><del>-if py3k: - class ColumnIdentityMixin(object): - def __hash_func__(self, obj): - if hasattr(obj, '__sa_hash_key__'): - return obj.__sa_hash_key__() - else: - return obj.__hash__() - - class column_set(ColumnIdentityMixin, IdentitySet): - pass - class column_dict(ColumnIdentityMixin, IdentityDict): - pass - class ordered_column_set(ColumnIdentityMixin, OrderedIdentitySet): - pass - class populate_column_dict(ColumnIdentityMixin, PopulateIdentityDict): - pass -else: - column_set = set - column_dict = dict - ordered_column_set = OrderedSet - populate_column_dict = PopulateDict - -class _id_tuple(tuple): - def __new__(cls, value, fn): - return tuple.__new__(cls, [fn(value), value]) - - def __hash__(self): - return self[0] - - def __eq__(self, other): - return self[0] == other[0] - -def _iter_id(iterable, fn): </del><ins>+def _iter_id(iterable): </ins><span class="cx"> """Generator: ((id(o), o) for o in iterable).""" </span><ins>+ </ins><span class="cx"> for item in iterable: </span><del>- yield _id_tuple(item, fn) - #yield id(item), item </del><ins>+ yield id(item), item </ins><span class="cx"> </span><ins>+ +column_set = set +column_dict = dict +ordered_column_set = OrderedSet +populate_column_dict = PopulateDict + </ins><span class="cx"> def unique_list(seq, compare_with=set): </span><span class="cx"> seen = compare_with() </span><span class="cx"> return [x for x in seq if x not in seen and not seen.add(x)] </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningstestbaseutilspy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/test/base/utils.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/test/base/utils.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/test/base/utils.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -262,23 +262,19 @@ </span><span class="cx"> </span><span class="cx"> class OrderedIdentitySetTest(unittest.TestCase): </span><span class="cx"> </span><del>- class Unhashable(object): - def __hash__(self): - raise NotImplementedError() - </del><span class="cx"> def assert_eq(self, identityset, expected_iterable): </span><span class="cx"> expected = [id(o) for o in expected_iterable] </span><span class="cx"> found = [id(o) for o in identityset] </span><span class="cx"> eq_(found, expected) </span><span class="cx"> </span><span class="cx"> def test_add(self): </span><del>- elem = self.Unhashable </del><ins>+ elem = object </ins><span class="cx"> s = util.OrderedIdentitySet() </span><span class="cx"> s.add(elem()) </span><span class="cx"> s.add(elem()) </span><span class="cx"> </span><span class="cx"> def test_intersection(self): </span><del>- elem = self.Unhashable </del><ins>+ elem = object </ins><span class="cx"> eq_ = self.assert_eq </span><span class="cx"> </span><span class="cx"> a, b, c, d, e, f, g = elem(), elem(), elem(), elem(), elem(), elem(), elem() </span></span></pre></div> <a id="sqlalchemybranchespy3k_warningstesttestlibfixturespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/py3k_warnings/test/testlib/fixtures.py (5301 => 5302)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/py3k_warnings/test/testlib/fixtures.py 2008-11-17 00:30:05 UTC (rev 5301) +++ sqlalchemy/branches/py3k_warnings/test/testlib/fixtures.py 2008-11-17 00:31:23 UTC (rev 5302) </span><span class="lines">@@ -25,6 +25,8 @@ </span><span class="cx"> def __ne__(self, other): </span><span class="cx"> return not self.__eq__(other) </span><span class="cx"> </span><ins>+ __hash__ = object.__hash__ + </ins><span class="cx"> def __eq__(self, other): </span><span class="cx"> """'passively' compare this object to another. </span><span class="cx"> </span></span></pre> </div> </div> </body> </html> |