summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/naming.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/sql/naming.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/sql/naming.py')
-rw-r--r--lib/sqlalchemy/sql/naming.py47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index 0107ce724..144cc4dfc 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -10,8 +10,16 @@
"""
-from .schema import Constraint, ForeignKeyConstraint, PrimaryKeyConstraint, \
- UniqueConstraint, CheckConstraint, Index, Table, Column
+from .schema import (
+ Constraint,
+ ForeignKeyConstraint,
+ PrimaryKeyConstraint,
+ UniqueConstraint,
+ CheckConstraint,
+ Index,
+ Table,
+ Column,
+)
from .. import event, events
from .. import exc
from .elements import _truncated_label, _defer_name, _defer_none_name, conv
@@ -19,7 +27,6 @@ import re
class ConventionDict(object):
-
def __init__(self, const, table, convention):
self.const = const
self._is_fk = isinstance(const, ForeignKeyConstraint)
@@ -79,8 +86,8 @@ class ConventionDict(object):
def __getitem__(self, key):
if key in self.convention:
return self.convention[key](self.const, self.table)
- elif hasattr(self, '_key_%s' % key):
- return getattr(self, '_key_%s' % key)()
+ elif hasattr(self, "_key_%s" % key):
+ return getattr(self, "_key_%s" % key)()
else:
col_template = re.match(r".*_?column_(\d+)(_?N)?_.+", key)
if col_template:
@@ -108,12 +115,13 @@ class ConventionDict(object):
return getattr(self, attr)(idx)
raise KeyError(key)
+
_prefix_dict = {
Index: "ix",
PrimaryKeyConstraint: "pk",
CheckConstraint: "ck",
UniqueConstraint: "uq",
- ForeignKeyConstraint: "fk"
+ ForeignKeyConstraint: "fk",
}
@@ -134,15 +142,18 @@ def _constraint_name_for_table(const, table):
if isinstance(const.name, conv):
return const.name
- elif convention is not None and \
- not isinstance(const.name, conv) and \
- (
- const.name is None or
- "constraint_name" in convention or
- isinstance(const.name, _defer_name)):
+ elif (
+ convention is not None
+ and not isinstance(const.name, conv)
+ and (
+ const.name is None
+ or "constraint_name" in convention
+ or isinstance(const.name, _defer_name)
+ )
+ ):
return conv(
- convention % ConventionDict(const, table,
- metadata.naming_convention)
+ convention
+ % ConventionDict(const, table, metadata.naming_convention)
)
elif isinstance(convention, _defer_none_name):
return None
@@ -155,9 +166,11 @@ def _constraint_name(const, table):
# for column-attached constraint, set another event
# to link the column attached to the table as this constraint
# associated with the table.
- event.listen(table, "after_parent_attach",
- lambda col, table: _constraint_name(const, table)
- )
+ event.listen(
+ table,
+ "after_parent_attach",
+ lambda col, table: _constraint_name(const, table),
+ )
elif isinstance(table, Table):
if isinstance(const.name, (conv, _defer_name)):
return