From: Mike Bayer Date: Sat, 9 Mar 2013 23:22:14 +0000 (-0500) Subject: linting X-Git-Tag: rel_0_8_0~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25e732fe48cdd73083ffba12ec961846eabbd2ec;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git linting --- diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index d9dfff77d8..e225a7c83c 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -154,7 +154,7 @@ def _organize_states_for_save(base_mapper, states, uowtransaction): # with the same identity key already exists as persistent. # convert to an UPDATE if so. if not has_identity and \ - instance_key in uowtransaction.session.identity_map: + instance_key in uowtransaction.session.identity_map: instance = \ uowtransaction.session.identity_map[instance_key] existing = attributes.instance_state(instance) diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index fd0c54d885..9e44e01f72 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -352,7 +352,7 @@ class JoinCondition(object): return if "foreign" not in binary.left._annotations and \ - "foreign" not in binary.right._annotations: + "foreign" not in binary.right._annotations: col = is_foreign(binary.left, binary.right) if col is not None: if col.compare(binary.left): @@ -451,12 +451,11 @@ class JoinCondition(object): def visit_binary(binary): equated = binary.left.compare(binary.right) if isinstance(binary.left, expression.ColumnClause) and \ - isinstance(binary.right, expression.ColumnClause): + isinstance(binary.right, expression.ColumnClause): # assume one to many - FKs are "remote" if fn(binary.left): binary.left = binary.left._annotate({"remote": True}) - if fn(binary.right) and \ - not equated: + if fn(binary.right) and not equated: binary.right = binary.right._annotate( {"remote": True}) else: @@ -507,9 +506,9 @@ class JoinCondition(object): def proc_left_right(left, right): if isinstance(left, expression.ColumnClause) and \ - isinstance(right, expression.ColumnClause): + isinstance(right, expression.ColumnClause): if self.child_selectable.c.contains_column(right) and \ - self.parent_selectable.c.contains_column(left): + self.parent_selectable.c.contains_column(left): right = right._annotate({"remote": True}) else: self._warn_non_column_elements() @@ -532,8 +531,7 @@ class JoinCondition(object): not self.parent_local_selectable.c.\ contains_column(element) or self.child_local_selectable.c.\ - contains_column(element) - ): + contains_column(element)): return element._annotate({"remote": True}) self.primaryjoin = visitors.replacement_traverse( self.primaryjoin, {}, repl) @@ -568,7 +566,7 @@ class JoinCondition(object): def locals_(elem): if "remote" not in elem._annotations and \ - elem in local_side: + elem in local_side: return elem._annotate({"local": True}) self.primaryjoin = visitors.replacement_traverse( self.primaryjoin, {}, locals_ @@ -603,7 +601,7 @@ class JoinCondition(object): can_sync = bool(self.secondary_synchronize_pairs) if self.support_sync and can_sync or \ - (not self.support_sync and has_foreign): + (not self.support_sync and has_foreign): return # from here below is just determining the best error message @@ -685,8 +683,7 @@ class JoinCondition(object): "Ensure that only those columns referring " "to a parent column are marked as foreign, " "either via the foreign() annotation or " - "via the foreign_keys argument." - % self.prop) + "via the foreign_keys argument." % self.prop) elif onetomany_fk: self.direction = ONETOMANY elif manytoone_fk: @@ -716,14 +713,14 @@ class JoinCondition(object): def visit_binary(binary, left, right): if "remote" in right._annotations and \ "remote" not in left._annotations and \ - self.can_be_synced_fn(left): + self.can_be_synced_fn(left): lrp.add((left, right)) elif "remote" in left._annotations and \ "remote" not in right._annotations and \ - self.can_be_synced_fn(right): + self.can_be_synced_fn(right): lrp.add((right, left)) if binary.operator is operators.eq and \ - self.can_be_synced_fn(left, right): + self.can_be_synced_fn(left, right): if "foreign" in right._annotations: collection.append((left, right)) elif "foreign" in left._annotations: diff --git a/test/orm/test_rel_fn.py b/test/orm/test_rel_fn.py index cd871661b6..10ba41429d 100644 --- a/test/orm/test_rel_fn.py +++ b/test/orm/test_rel_fn.py @@ -1,4 +1,4 @@ -from sqlalchemy.testing import assert_raises, assert_raises_message, eq_, \ +from sqlalchemy.testing import assert_raises_message, eq_, \ AssertsCompiledSQL, is_ from sqlalchemy.testing import fixtures from sqlalchemy.orm import relationships, foreign, remote @@ -119,9 +119,9 @@ class _JoinFixtures(object): support_sync=False, can_be_synced_fn=_can_sync, primaryjoin=and_( - self.three_tab_a.c.id==self.three_tab_b.c.aid, - self.three_tab_c.c.bid==self.three_tab_b.c.id, - self.three_tab_c.c.aid==self.three_tab_a.c.id + self.three_tab_a.c.id == self.three_tab_b.c.aid, + self.three_tab_c.c.bid == self.three_tab_b.c.id, + self.three_tab_c.c.aid == self.three_tab_a.c.id ) ) @@ -215,9 +215,9 @@ class _JoinFixtures(object): self.composite_selfref, self.composite_selfref, primaryjoin=and_( - self.composite_selfref.c.group_id== + self.composite_selfref.c.group_id == func.foo(self.composite_selfref.c.group_id), - self.composite_selfref.c.parent_id== + self.composite_selfref.c.parent_id == self.composite_selfref.c.id ), **kw @@ -230,9 +230,9 @@ class _JoinFixtures(object): self.composite_selfref, self.composite_selfref, primaryjoin=and_( - remote(self.composite_selfref.c.group_id)== + remote(self.composite_selfref.c.group_id) == func.foo(self.composite_selfref.c.group_id), - remote(self.composite_selfref.c.parent_id)== + remote(self.composite_selfref.c.parent_id) == self.composite_selfref.c.id ), **kw @@ -281,58 +281,60 @@ class _JoinFixtures(object): # see test/orm/inheritance/test_abc_inheritance:TestaTobM2O # and others there right = self.base_w_sub_rel.join(self.rel_sub, - self.base_w_sub_rel.c.id==self.rel_sub.c.id + self.base_w_sub_rel.c.id == self.rel_sub.c.id ) return relationships.JoinCondition( self.base_w_sub_rel, right, self.base_w_sub_rel, self.rel_sub, - primaryjoin=self.base_w_sub_rel.c.sub_id==\ + primaryjoin=self.base_w_sub_rel.c.sub_id == \ self.rel_sub.c.id, **kw ) def _join_fixture_o2m_joined_sub_to_base(self, **kw): left = self.base.join(self.sub_w_base_rel, - self.base.c.id==self.sub_w_base_rel.c.id) + self.base.c.id == self.sub_w_base_rel.c.id) return relationships.JoinCondition( left, self.base, self.sub_w_base_rel, self.base, - primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id + primaryjoin=self.sub_w_base_rel.c.base_id == self.base.c.id ) def _join_fixture_m2o_joined_sub_to_sub_on_base(self, **kw): # this is a late add - a variant of the test case # in #2491 where we join on the base cols instead. only # m2o has a problem at the time of this test. - left = self.base.join(self.sub, self.base.c.id==self.sub.c.id) - right = self.base.join(self.sub_w_base_rel, self.base.c.id==self.sub_w_base_rel.c.id) + left = self.base.join(self.sub, self.base.c.id == self.sub.c.id) + right = self.base.join(self.sub_w_base_rel, + self.base.c.id == self.sub_w_base_rel.c.id) return relationships.JoinCondition( left, right, self.sub, self.sub_w_base_rel, - primaryjoin=self.sub_w_base_rel.c.base_id==self.base.c.id, + primaryjoin=self.sub_w_base_rel.c.base_id == self.base.c.id, ) def _join_fixture_o2m_joined_sub_to_sub(self, **kw): - left = self.base.join(self.sub, self.base.c.id==self.sub.c.id) - right = self.base.join(self.sub_w_sub_rel, self.base.c.id==self.sub_w_sub_rel.c.id) + left = self.base.join(self.sub, self.base.c.id == self.sub.c.id) + right = self.base.join(self.sub_w_sub_rel, + self.base.c.id == self.sub_w_sub_rel.c.id) return relationships.JoinCondition( left, right, self.sub, self.sub_w_sub_rel, - primaryjoin=self.sub.c.id==self.sub_w_sub_rel.c.sub_id + primaryjoin=self.sub.c.id == self.sub_w_sub_rel.c.sub_id ) def _join_fixture_m2o_sub_to_joined_sub(self, **kw): # see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate, right = self.base.join(self.right_w_base_rel, - self.base.c.id==self.right_w_base_rel.c.id) + self.base.c.id == self.right_w_base_rel.c.id) return relationships.JoinCondition( self.right_w_base_rel, right, @@ -343,19 +345,19 @@ class _JoinFixtures(object): def _join_fixture_m2o_sub_to_joined_sub_func(self, **kw): # see test.orm.test_mapper:MapperTest.test_add_column_prop_deannotate, right = self.base.join(self.right_w_base_rel, - self.base.c.id==self.right_w_base_rel.c.id) + self.base.c.id == self.right_w_base_rel.c.id) return relationships.JoinCondition( self.right_w_base_rel, right, self.right_w_base_rel, self.right_w_base_rel, - primaryjoin=self.right_w_base_rel.c.base_id==\ + primaryjoin=self.right_w_base_rel.c.base_id == \ func.foo(self.base.c.id) ) def _join_fixture_o2o_joined_sub_to_base(self, **kw): left = self.base.join(self.sub, - self.base.c.id==self.sub.c.id) + self.base.c.id == self.sub.c.id) # see test_relationships->AmbiguousJoinInterpretedAsSelfRef return relationships.JoinCondition( @@ -371,7 +373,7 @@ class _JoinFixtures(object): self.right, self.left, self.right, - primaryjoin=self.left.c.id== + primaryjoin=self.left.c.id == foreign(func.foo(self.right.c.lid)), **kw ) @@ -382,7 +384,7 @@ class _JoinFixtures(object): self.right, self.left, self.right, - primaryjoin=self.left.c.id== + primaryjoin=self.left.c.id == func.foo(self.right.c.lid), consider_as_foreign_keys=[self.right.c.lid], **kw @@ -399,7 +401,7 @@ class _JoinFixtures(object): ) def _assert_raises_no_relevant_fks(self, fn, expr, relname, - primary, *arg, **kw): + primary, *arg, **kw): assert_raises_message( exc.ArgumentError, r"Could not locate any relevant foreign key columns " @@ -414,9 +416,9 @@ class _JoinFixtures(object): ) def _assert_raises_no_equality(self, fn, expr, relname, - primary, *arg, **kw): + primary, *arg, **kw): assert_raises_message( - sa.exc.ArgumentError, + exc.ArgumentError, "Could not locate any simple equality expressions " "involving locally mapped foreign key columns for %s join " "condition '%s' on relationship %s. " @@ -431,7 +433,7 @@ class _JoinFixtures(object): ) def _assert_raises_ambig_join(self, fn, relname, secondary_arg, - *arg, **kw): + *arg, **kw): if secondary_arg is not None: assert_raises_message( exc.AmbiguousForeignKeysError, @@ -455,7 +457,7 @@ class _JoinFixtures(object): fn, *arg, **kw) def _assert_raises_no_join(self, fn, relname, secondary_arg, - *arg, **kw): + *arg, **kw): if secondary_arg is not None: assert_raises_message( exc.NoForeignKeysError, @@ -463,7 +465,8 @@ class _JoinFixtures(object): "parent/child tables on relationship %s - " "there are no foreign keys linking these tables " "via secondary table '%s'. " - "Ensure that referencing columns are associated with a ForeignKey " + "Ensure that referencing columns are associated " + "with a ForeignKey " "or ForeignKeyConstraint, or specify 'primaryjoin' and " "'secondaryjoin' expressions" % (relname, secondary_arg), @@ -474,14 +477,16 @@ class _JoinFixtures(object): "Could not determine join condition between " "parent/child tables on relationship %s - " "there are no foreign keys linking these tables. " - "Ensure that referencing columns are associated with a ForeignKey " + "Ensure that referencing columns are associated " + "with a ForeignKey " "or ForeignKeyConstraint, or specify a 'primaryjoin' " "expression." % (relname,), fn, *arg, **kw) -class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL): +class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, + AssertsCompiledSQL): def test_determine_local_remote_pairs_o2o_joined_sub_to_base(self): joincond = self._join_fixture_o2o_joined_sub_to_base() eq_( @@ -580,7 +585,7 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL ] ) - def test_determine_local_remote_compound_1(self): + def test_determine_local_remote_compound_3(self): joincond = self._join_fixture_compound_expression_1() eq_( joincond.local_remote_pairs, @@ -627,8 +632,10 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL eq_( joincond.local_remote_pairs, [ - (self.composite_selfref.c.group_id, self.composite_selfref.c.group_id), - (self.composite_selfref.c.id, self.composite_selfref.c.parent_id), + (self.composite_selfref.c.group_id, + self.composite_selfref.c.group_id), + (self.composite_selfref.c.id, + self.composite_selfref.c.parent_id), ] ) @@ -647,8 +654,10 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL eq_( joincond.local_remote_pairs, [ - (self.composite_selfref.c.group_id, self.composite_selfref.c.group_id), - (self.composite_selfref.c.id, self.composite_selfref.c.parent_id), + (self.composite_selfref.c.group_id, + self.composite_selfref.c.group_id), + (self.composite_selfref.c.id, + self.composite_selfref.c.parent_id), ] ) @@ -713,8 +722,8 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL eq_( j2.local_remote_pairs, [ - (self.m2mright.c.id, self.m2msecondary.c.rid), - (self.m2mleft.c.id, self.m2msecondary.c.lid), + (self.m2mright.c.id, self.m2msecondary.c.rid), + (self.m2mleft.c.id, self.m2msecondary.c.lid), ] )