summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/array.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /lib/sqlalchemy/dialects/postgresql/array.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-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/array.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/array.py79
1 files changed, 52 insertions, 27 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py
index b2674046e..07167f9d0 100644
--- a/lib/sqlalchemy/dialects/postgresql/array.py
+++ b/lib/sqlalchemy/dialects/postgresql/array.py
@@ -78,7 +78,8 @@ class array(expression.Tuple):
:class:`.postgresql.ARRAY`
"""
- __visit_name__ = 'array'
+
+ __visit_name__ = "array"
def __init__(self, clauses, **kw):
super(array, self).__init__(*clauses, **kw)
@@ -90,18 +91,26 @@ class array(expression.Tuple):
# a Slice object from that
assert isinstance(obj, int)
return expression.BindParameter(
- None, obj, _compared_to_operator=operator,
+ None,
+ obj,
+ _compared_to_operator=operator,
type_=type_,
- _compared_to_type=self.type, unique=True)
+ _compared_to_type=self.type,
+ unique=True,
+ )
else:
- return array([
- self._bind_param(operator, o, _assume_scalar=True, type_=type_)
- for o in obj])
+ return array(
+ [
+ self._bind_param(
+ operator, o, _assume_scalar=True, type_=type_
+ )
+ for o in obj
+ ]
+ )
def self_group(self, against=None):
- if (against in (
- operators.any_op, operators.all_op, operators.getitem)):
+ if against in (operators.any_op, operators.all_op, operators.getitem):
return expression.Grouping(self)
else:
return self
@@ -180,7 +189,8 @@ class ARRAY(sqltypes.ARRAY):
elements of the argument array expression.
"""
return self.operate(
- CONTAINED_BY, other, result_type=sqltypes.Boolean)
+ CONTAINED_BY, other, result_type=sqltypes.Boolean
+ )
def overlap(self, other):
"""Boolean expression. Test if array has elements in common with
@@ -190,8 +200,9 @@ class ARRAY(sqltypes.ARRAY):
comparator_factory = Comparator
- def __init__(self, item_type, as_tuple=False, dimensions=None,
- zero_indexes=False):
+ def __init__(
+ self, item_type, as_tuple=False, dimensions=None, zero_indexes=False
+ ):
"""Construct an ARRAY.
E.g.::
@@ -228,8 +239,10 @@ class ARRAY(sqltypes.ARRAY):
"""
if isinstance(item_type, ARRAY):
- raise ValueError("Do not nest ARRAY types; ARRAY(basetype) "
- "handles multi-dimensional arrays of basetype")
+ raise ValueError(
+ "Do not nest ARRAY types; ARRAY(basetype) "
+ "handles multi-dimensional arrays of basetype"
+ )
if isinstance(item_type, type):
item_type = item_type()
self.item_type = item_type
@@ -251,11 +264,17 @@ class ARRAY(sqltypes.ARRAY):
def _proc_array(self, arr, itemproc, dim, collection):
if dim is None:
arr = list(arr)
- if dim == 1 or dim is None and (
+ if (
+ dim == 1
+ or dim is None
+ and (
# this has to be (list, tuple), or at least
# not hasattr('__iter__'), since Py3K strings
# etc. have __iter__
- not arr or not isinstance(arr[0], (list, tuple))):
+ not arr
+ or not isinstance(arr[0], (list, tuple))
+ )
+ ):
if itemproc:
return collection(itemproc(x) for x in arr)
else:
@@ -263,30 +282,33 @@ class ARRAY(sqltypes.ARRAY):
else:
return collection(
self._proc_array(
- x, itemproc,
+ x,
+ itemproc,
dim - 1 if dim is not None else None,
- collection)
+ collection,
+ )
for x in arr
)
def bind_processor(self, dialect):
- item_proc = self.item_type.dialect_impl(dialect).\
- bind_processor(dialect)
+ item_proc = self.item_type.dialect_impl(dialect).bind_processor(
+ dialect
+ )
def process(value):
if value is None:
return value
else:
return self._proc_array(
- value,
- item_proc,
- self.dimensions,
- list)
+ value, item_proc, self.dimensions, list
+ )
+
return process
def result_processor(self, dialect, coltype):
- item_proc = self.item_type.dialect_impl(dialect).\
- result_processor(dialect, coltype)
+ item_proc = self.item_type.dialect_impl(dialect).result_processor(
+ dialect, coltype
+ )
def process(value):
if value is None:
@@ -296,8 +318,11 @@ class ARRAY(sqltypes.ARRAY):
value,
item_proc,
self.dimensions,
- tuple if self.as_tuple else list)
+ tuple if self.as_tuple else list,
+ )
+
return process
+
colspecs[sqltypes.ARRAY] = ARRAY
-ischema_names['_array'] = ARRAY
+ischema_names["_array"] = ARRAY