diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-11-03 20:52:21 +0100 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2022-11-16 23:03:04 +0100 |
commit | 4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66 (patch) | |
tree | 4970cff3f78489a4a0066cd27fd4bae682402957 /lib/sqlalchemy/sql/selectable.py | |
parent | 3fc6c40ea77c971d3067dab0fdf57a5b5313b69b (diff) | |
download | sqlalchemy-4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66.tar.gz |
Try running pyupgrade on the code
command run is "pyupgrade --py37-plus --keep-runtime-typing --keep-percent-format <files...>"
pyupgrade will change assert_ to assertTrue. That was reverted since assertTrue does not
exists in sqlalchemy fixtures
Change-Id: Ie1ed2675c7b11d893d78e028aad0d1576baebb55
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 8c64dea9d..fcffc324f 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1301,12 +1301,12 @@ class Join(roles.DMLTableRole, FromClause): # run normal _copy_internals. the clones for # left and right will come from the clone function's # cache - super(Join, self)._copy_internals(clone=clone, **kw) + super()._copy_internals(clone=clone, **kw) self._reset_memoizations() def _refresh_for_new_column(self, column: ColumnElement[Any]) -> None: - super(Join, self)._refresh_for_new_column(column) + super()._refresh_for_new_column(column) self.left._refresh_for_new_column(column) self.right._refresh_for_new_column(column) @@ -1467,7 +1467,7 @@ class Join(roles.DMLTableRole, FromClause): # "consider_as_foreign_keys". if consider_as_foreign_keys: for const in list(constraints): - if set(f.parent for f in const.elements) != set( + if {f.parent for f in const.elements} != set( consider_as_foreign_keys ): del constraints[const] @@ -1475,7 +1475,7 @@ class Join(roles.DMLTableRole, FromClause): # if still multiple constraints, but # they all refer to the exact same end result, use it. if len(constraints) > 1: - dedupe = set(tuple(crit) for crit in constraints.values()) + dedupe = {tuple(crit) for crit in constraints.values()} if len(dedupe) == 1: key = list(constraints)[0] constraints = {key: constraints[key]} @@ -1621,7 +1621,7 @@ class AliasedReturnsRows(NoInit, NamedFromClause): self.name = name def _refresh_for_new_column(self, column: ColumnElement[Any]) -> None: - super(AliasedReturnsRows, self)._refresh_for_new_column(column) + super()._refresh_for_new_column(column) self.element._refresh_for_new_column(column) def _populate_column_collection(self): @@ -1654,7 +1654,7 @@ class AliasedReturnsRows(NoInit, NamedFromClause): ) -> None: existing_element = self.element - super(AliasedReturnsRows, self)._copy_internals(clone=clone, **kw) + super()._copy_internals(clone=clone, **kw) # the element clone is usually against a Table that returns the # same object. don't reset exported .c. collections and other @@ -1752,7 +1752,7 @@ class TableValuedAlias(LateralFromClause, Alias): table_value_type=None, joins_implicitly=False, ): - super(TableValuedAlias, self)._init(selectable, name=name) + super()._init(selectable, name=name) self.joins_implicitly = joins_implicitly self._tableval_type = ( @@ -1959,7 +1959,7 @@ class TableSample(FromClauseAlias): self.sampling = sampling self.seed = seed - super(TableSample, self)._init(selectable, name=name) + super()._init(selectable, name=name) def _get_method(self): return self.sampling @@ -2044,7 +2044,7 @@ class CTE( self._prefixes = _prefixes if _suffixes: self._suffixes = _suffixes - super(CTE, self)._init(selectable, name=name) + super()._init(selectable, name=name) def _populate_column_collection(self): if self._cte_alias is not None: @@ -2945,7 +2945,7 @@ class TableClause(roles.DMLTableRole, Immutable, NamedFromClause): return None def __init__(self, name: str, *columns: ColumnClause[Any], **kw: Any): - super(TableClause, self).__init__() + super().__init__() self.name = name self._columns = DedupeColumnCollection() self.primary_key = ColumnSet() # type: ignore @@ -3156,7 +3156,7 @@ class Values(Generative, LateralFromClause): name: Optional[str] = None, literal_binds: bool = False, ): - super(Values, self).__init__() + super().__init__() self._column_args = columns if name is None: self._unnamed = True @@ -4188,7 +4188,7 @@ class CompoundSelectState(CompileState): # TODO: this is hacky and slow hacky_subquery = self.statement.subquery() hacky_subquery.named_with_column = False - d = dict((c.key, c) for c in hacky_subquery.c) + d = {c.key: c for c in hacky_subquery.c} return d, d, d @@ -4369,7 +4369,7 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows): ) def _refresh_for_new_column(self, column): - super(CompoundSelect, self)._refresh_for_new_column(column) + super()._refresh_for_new_column(column) for select in self.selects: select._refresh_for_new_column(column) @@ -4689,16 +4689,16 @@ class SelectState(util.MemoizedSlots, CompileState): Dict[str, ColumnElement[Any]], Dict[str, ColumnElement[Any]], ]: - with_cols: Dict[str, ColumnElement[Any]] = dict( - (c._tq_label or c.key, c) # type: ignore + with_cols: Dict[str, ColumnElement[Any]] = { + c._tq_label or c.key: c # type: ignore for c in self.statement._all_selected_columns if c._allow_label_resolve - ) - only_froms: Dict[str, ColumnElement[Any]] = dict( - (c.key, c) # type: ignore + } + only_froms: Dict[str, ColumnElement[Any]] = { + c.key: c # type: ignore for c in _select_iterables(self.froms) if c._allow_label_resolve - ) + } only_cols: Dict[str, ColumnElement[Any]] = with_cols.copy() for key, value in only_froms.items(): with_cols.setdefault(key, value) @@ -5569,7 +5569,7 @@ class Select( # 2. copy FROM collections, adding in joins that we've created. existing_from_obj = [clone(f, **kw) for f in self._from_obj] add_froms = ( - set(f for f in new_froms.values() if isinstance(f, Join)) + {f for f in new_froms.values() if isinstance(f, Join)} .difference(all_the_froms) .difference(existing_from_obj) ) @@ -5589,15 +5589,13 @@ class Select( # correlate_except, setup_joins, these clone normally. For # column-expression oriented things like raw_columns, where_criteria, # order by, we get this from the new froms. - super(Select, self)._copy_internals( - clone=clone, omit_attrs=("_from_obj",), **kw - ) + super()._copy_internals(clone=clone, omit_attrs=("_from_obj",), **kw) self._reset_memoizations() def get_children(self, **kw: Any) -> Iterable[ClauseElement]: return itertools.chain( - super(Select, self).get_children( + super().get_children( omit_attrs=("_from_obj", "_correlate", "_correlate_except"), **kw, ), |