@@ -876,9 +876,7 @@ def from_(self, selectable: Selectable | Query | str) -> Self: # type:ignore[re
876876 """
877877
878878 self ._from .append (
879- Table (selectable )
880- if isinstance (selectable , str )
881- else selectable # type:ignore[arg-type]
879+ Table (selectable ) if isinstance (selectable , str ) else selectable # type:ignore[arg-type]
882880 )
883881
884882 if isinstance (selectable , (QueryBuilder , _SetOperation )) and selectable .alias is None :
@@ -1131,7 +1129,7 @@ def with_totals(self) -> Self: # type:ignore[return]
11311129 def rollup ( # type:ignore[return]
11321130 self , * terms : list | tuple | set | Term , ** kwargs : Any
11331131 ) -> Self :
1134- for_mysql = "mysql" == kwargs .get ("vendor" )
1132+ for_mysql = kwargs .get ("vendor" ) == "mysql"
11351133
11361134 if self ._mysql_rollup :
11371135 raise AttributeError ("'Query' object has no attribute '%s'" % "rollup" )
@@ -1151,7 +1149,7 @@ def rollup( # type:ignore[return]
11511149 self ._mysql_rollup = True
11521150 self ._groupbys += terms # type:ignore[arg-type]
11531151
1154- elif 0 < len (self ._groupbys ) and isinstance (self ._groupbys [- 1 ], Rollup ):
1152+ elif len (self ._groupbys ) > 0 and isinstance (self ._groupbys [- 1 ], Rollup ):
11551153 # If a rollup was added last, then append the new terms to the previous rollup
11561154 self ._groupbys [- 1 ].args += terms
11571155
@@ -1278,7 +1276,7 @@ def _list_aliases(field_set: Sequence[Field], ctx: SqlContext) -> list[str]:
12781276 return [field .alias or field .get_sql (ctx ) for field in field_set ]
12791277
12801278 def _select_field_str (self , term : str ) -> None :
1281- if 0 == len (self ._from ):
1279+ if len (self ._from ) == 0 :
12821280 raise QueryException (f"Cannot select { term } , no FROM table specified." ) # nosec:B608
12831281
12841282 if term == "*" :
@@ -1399,8 +1397,8 @@ def get_sql(self, ctx: SqlContext | None = None) -> str:
13991397 return ""
14001398
14011399 has_joins = bool (self ._joins )
1402- has_multiple_from_clauses = 1 < len (self ._from )
1403- has_subquery_from_clause = 0 < len (self ._from ) and isinstance (self ._from [0 ], QueryBuilder )
1400+ has_multiple_from_clauses = len (self ._from ) > 1
1401+ has_subquery_from_clause = len (self ._from ) > 0 and isinstance (self ._from [0 ], QueryBuilder )
14041402 has_reference_to_foreign_table = self ._foreign_table
14051403 has_update_from = self ._update_table and self ._from
14061404
@@ -1417,11 +1415,7 @@ def get_sql(self, ctx: SqlContext | None = None) -> str:
14171415 )
14181416
14191417 if self ._update_table :
1420- if self ._with :
1421- querystring = self ._with_sql (ctx )
1422- else :
1423- querystring = ""
1424-
1418+ querystring = self ._with_sql (ctx ) if self ._with else ""
14251419 querystring += self ._update_sql (ctx )
14261420
14271421 if self ._joins :
@@ -1441,10 +1435,7 @@ def get_sql(self, ctx: SqlContext | None = None) -> str:
14411435 querystring = self ._delete_sql (ctx )
14421436
14431437 elif not self ._select_into and self ._insert_table :
1444- if self ._with :
1445- querystring = self ._with_sql (ctx )
1446- else :
1447- querystring = ""
1438+ querystring = self ._with_sql (ctx ) if self ._with else ""
14481439
14491440 if self ._replace :
14501441 querystring += self ._replace_sql (ctx )
@@ -1464,11 +1455,7 @@ def get_sql(self, ctx: SqlContext | None = None) -> str:
14641455 querystring += " " + self ._select_sql (ctx )
14651456
14661457 else :
1467- if self ._with :
1468- querystring = self ._with_sql (ctx )
1469- else :
1470- querystring = ""
1471-
1458+ querystring = self ._with_sql (ctx ) if self ._with else ""
14721459 querystring += self ._select_sql (ctx )
14731460
14741461 if self ._insert_table :
@@ -1568,7 +1555,7 @@ def _for_update_sql(self, ctx: SqlContext, lock_strength="UPDATE") -> str:
15681555 for_update = f" FOR { lock_strength } "
15691556 if self ._for_update_of :
15701557 for_update += (
1571- f' OF { ", " .join ([Table (item ).get_sql (ctx ) for item in self ._for_update_of ])} '
1558+ f" OF { ', ' .join ([Table (item ).get_sql (ctx ) for item in self ._for_update_of ])} "
15721559 )
15731560 if self ._for_update_nowait :
15741561 for_update += " NOWAIT"
@@ -1761,8 +1748,9 @@ def __init__(
17611748 def on (self , criterion : Criterion | None , collate : str | None = None ) -> QueryBuilder :
17621749 if criterion is None :
17631750 raise JoinException (
1764- "Parameter 'criterion' is required for a "
1765- "{type} JOIN but was not supplied." .format (type = self .type_label )
1751+ "Parameter 'criterion' is required for a {type} JOIN but was not supplied." .format (
1752+ type = self .type_label
1753+ )
17661754 )
17671755
17681756 self .query .do_join (JoinOn (self .item , self .how , criterion , collate )) # type:ignore[arg-type]
@@ -1771,8 +1759,9 @@ def on(self, criterion: Criterion | None, collate: str | None = None) -> QueryBu
17711759 def on_field (self , * fields : Any ) -> QueryBuilder :
17721760 if not fields :
17731761 raise JoinException (
1774- "Parameter 'fields' is required for a "
1775- "{type} JOIN but was not supplied." .format (type = self .type_label )
1762+ "Parameter 'fields' is required for a {type} JOIN but was not supplied." .format (
1763+ type = self .type_label
1764+ )
17761765 )
17771766
17781767 criterion = None
@@ -2181,7 +2170,8 @@ def _unique_key_clauses(self, ctx: SqlContext) -> list[str]:
21812170
21822171 def _primary_key_clause (self , ctx : SqlContext ) -> str :
21832172 columns = "," .join (
2184- column .get_name_sql (ctx ) for column in self ._primary_key # type:ignore[union-attr]
2173+ column .get_name_sql (ctx )
2174+ for column in self ._primary_key # type:ignore[union-attr]
21852175 )
21862176 return f"PRIMARY KEY ({ columns } )"
21872177
0 commit comments