diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-01-06 01:14:26 -0500 |
---|---|---|
committer | mike bayer <mike_mp@zzzcomputing.com> | 2019-01-06 17:34:50 +0000 |
commit | 1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch) | |
tree | 28e725c5c8188bd0cfd133d1e268dbca9b524978 /lib/sqlalchemy/dialects/postgresql/dml.py | |
parent | 404e69426b05a82d905cbb3ad33adafccddb00dd (diff) | |
download | sqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz |
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.
The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines. The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.
Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/dml.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/dml.py | 95 |
1 files changed, 53 insertions, 42 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/dml.py b/lib/sqlalchemy/dialects/postgresql/dml.py index 555a9006c..825f13238 100644 --- a/lib/sqlalchemy/dialects/postgresql/dml.py +++ b/lib/sqlalchemy/dialects/postgresql/dml.py @@ -14,7 +14,7 @@ from ...sql.base import _generative from ... import util from . import ext -__all__ = ('Insert', 'insert') +__all__ = ("Insert", "insert") class Insert(StandardInsert): @@ -40,13 +40,17 @@ class Insert(StandardInsert): to use :attr:`.Insert.excluded` """ - return alias(self.table, name='excluded').columns + return alias(self.table, name="excluded").columns @_generative def on_conflict_do_update( - self, - constraint=None, index_elements=None, - index_where=None, set_=None, where=None): + self, + constraint=None, + index_elements=None, + index_where=None, + set_=None, + where=None, + ): """ Specifies a DO UPDATE SET action for ON CONFLICT clause. @@ -96,13 +100,14 @@ class Insert(StandardInsert): """ self._post_values_clause = OnConflictDoUpdate( - constraint, index_elements, index_where, set_, where) + constraint, index_elements, index_where, set_, where + ) return self @_generative def on_conflict_do_nothing( - self, - constraint=None, index_elements=None, index_where=None): + self, constraint=None, index_elements=None, index_where=None + ): """ Specifies a DO NOTHING action for ON CONFLICT clause. @@ -130,30 +135,29 @@ class Insert(StandardInsert): """ self._post_values_clause = OnConflictDoNothing( - constraint, index_elements, index_where) + constraint, index_elements, index_where + ) return self -insert = public_factory(Insert, '.dialects.postgresql.insert') + +insert = public_factory(Insert, ".dialects.postgresql.insert") class OnConflictClause(ClauseElement): - def __init__( - self, - constraint=None, - index_elements=None, - index_where=None): + def __init__(self, constraint=None, index_elements=None, index_where=None): if constraint is not None: - if not isinstance(constraint, util.string_types) and \ - isinstance(constraint, ( - schema.Index, schema.Constraint, - ext.ExcludeConstraint)): - constraint = getattr(constraint, 'name') or constraint + if not isinstance(constraint, util.string_types) and isinstance( + constraint, + (schema.Index, schema.Constraint, ext.ExcludeConstraint), + ): + constraint = getattr(constraint, "name") or constraint if constraint is not None: if index_elements is not None: raise ValueError( - "'constraint' and 'index_elements' are mutually exclusive") + "'constraint' and 'index_elements' are mutually exclusive" + ) if isinstance(constraint, util.string_types): self.constraint_target = constraint @@ -161,54 +165,61 @@ class OnConflictClause(ClauseElement): self.inferred_target_whereclause = None elif isinstance(constraint, schema.Index): index_elements = constraint.expressions - index_where = \ - constraint.dialect_options['postgresql'].get("where") + index_where = constraint.dialect_options["postgresql"].get( + "where" + ) elif isinstance(constraint, ext.ExcludeConstraint): index_elements = constraint.columns index_where = constraint.where else: index_elements = constraint.columns - index_where = \ - constraint.dialect_options['postgresql'].get("where") + index_where = constraint.dialect_options["postgresql"].get( + "where" + ) if index_elements is not None: self.constraint_target = None self.inferred_target_elements = index_elements self.inferred_target_whereclause = index_where elif constraint is None: - self.constraint_target = self.inferred_target_elements = \ - self.inferred_target_whereclause = None + self.constraint_target = ( + self.inferred_target_elements + ) = self.inferred_target_whereclause = None class OnConflictDoNothing(OnConflictClause): - __visit_name__ = 'on_conflict_do_nothing' + __visit_name__ = "on_conflict_do_nothing" class OnConflictDoUpdate(OnConflictClause): - __visit_name__ = 'on_conflict_do_update' + __visit_name__ = "on_conflict_do_update" def __init__( - self, - constraint=None, - index_elements=None, - index_where=None, - set_=None, - where=None): + self, + constraint=None, + index_elements=None, + index_where=None, + set_=None, + where=None, + ): super(OnConflictDoUpdate, self).__init__( constraint=constraint, index_elements=index_elements, - index_where=index_where) + index_where=index_where, + ) - if self.inferred_target_elements is None and \ - self.constraint_target is None: + if ( + self.inferred_target_elements is None + and self.constraint_target is None + ): raise ValueError( "Either constraint or index_elements, " - "but not both, must be specified unless DO NOTHING") + "but not both, must be specified unless DO NOTHING" + ) - if (not isinstance(set_, dict) or not set_): + if not isinstance(set_, dict) or not set_: raise ValueError("set parameter must be a non-empty dictionary") self.update_values_to_set = [ - (key, value) - for key, value in set_.items() + (key, value) for key, value in set_.items() ] self.update_whereclause = where |