-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #2
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
modifier="{} ".format(" ".join(self._modifiers)) if self._modifiers else "", | ||
select=",".join(term.get_sql(with_alias=True, subquery=True, **kwargs) for term in self._selects), | ||
modifier=f'{" ".join(self._modifiers)} ' if self._modifiers else "", | ||
select=",".join( | ||
term.get_sql(with_alias=True, subquery=True, **kwargs) | ||
for term in self._selects | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MySQLQueryBuilder._select_sql
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return "LOAD DATA LOCAL INFILE '{}'".format(self._load_file) | ||
return f"LOAD DATA LOCAL INFILE '{self._load_file}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MySQLLoadQueryBuilder._load_file_sql
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return " FROM LOCAL '{}'".format(self._from_file) | ||
return f" FROM LOCAL '{self._from_file}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function VerticaCopyQueryBuilder._from_file_sql
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
def drop_database(self, database: Union[Database, str]) -> "ClickHouseDropQueryBuilder": | ||
def drop_database(cls, database: Union[Database, str]) -> "ClickHouseDropQueryBuilder": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ClickHouseQuery.drop_database
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
def drop_table(self, table: Union[Table, str]) -> "ClickHouseDropQueryBuilder": | ||
def drop_table(cls, table: Union[Table, str]) -> "ClickHouseDropQueryBuilder": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ClickHouseQuery.drop_table
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
if self._schema != other._schema: | ||
return False | ||
|
||
if self.alias != other.alias: | ||
return False | ||
|
||
return True | ||
return False if self._schema != other._schema else self.alias == other.alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Table.__eq__
refactored with the following changes:
- Lift code into else after jump in control flow [×2] (
reintroduce-else
) - Replace if statement with if expression [×2] (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
return "Table('{}', schema='{}')".format(self._table_name, self._schema) | ||
return "Table('{}')".format(self._table_name) | ||
return f"Table('{self._table_name}', schema='{self._schema}')" | ||
return f"Table('{self._table_name}')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Table.__repr__
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
column_sql = "{name}".format( | ||
return "{name}".format( | ||
name=format_quotes(self.name, quote_char), | ||
) | ||
|
||
return column_sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Column.get_name_sql
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
column_sql = "{name}{type}{nullable}{default}".format( | ||
return "{name}{type}{nullable}{default}".format( | ||
name=self.get_name_sql(**kwargs), | ||
type=" {}".format(self.type) if self.type else "", | ||
nullable=" {}".format("NULL" if self.nullable else "NOT NULL") if self.nullable is not None else "", | ||
default=" {}".format("DEFAULT " + self.default.get_sql(**kwargs)) if self.default else "", | ||
type=f" {self.type}" if self.type else "", | ||
nullable=f' {"NULL" if self.nullable else "NOT NULL"}' | ||
if self.nullable is not None | ||
else "", | ||
default=" {}".format(f"DEFAULT {self.default.get_sql(**kwargs)}") | ||
if self.default | ||
else "", | ||
) | ||
|
||
return column_sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Column.get_sql
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
period_for_sql = "PERIOD FOR {name} ({start_column_name},{end_column_name})".format( | ||
return "PERIOD FOR {name} ({start_column_name},{end_column_name})".format( | ||
name=format_quotes(self.name, quote_char), | ||
start_column_name=self.start_column.get_name_sql(**kwargs), | ||
end_column_name=self.end_column.get_name_sql(**kwargs), | ||
) | ||
|
||
return period_for_sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PeriodFor.get_sql
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
raise AttributeError("'Query' object has no attribute '%s'" % "into") | ||
raise AttributeError("'Query' object has no attribute 'into'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function QueryBuilder.into
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
raise AttributeError("'Query' object has no attribute '%s'" % "delete") | ||
raise AttributeError("'Query' object has no attribute 'delete'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function QueryBuilder.delete
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
raise AttributeError("'Query' object has no attribute '%s'" % "update") | ||
raise AttributeError("'Query' object has no attribute 'update'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function QueryBuilder.update
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
raise AttributeError("'Query' object has no attribute '%s'" % "insert") | ||
raise AttributeError("'Query' object has no attribute 'insert'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function QueryBuilder.columns
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
for_mysql = "mysql" == kwargs.get("vendor") | ||
for_mysql = kwargs.get("vendor") == "mysql" | ||
|
||
if self._mysql_rollup: | ||
raise AttributeError("'Query' object has no attribute '%s'" % "rollup") | ||
raise AttributeError("'Query' object has no attribute 'rollup'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function QueryBuilder.rollup
refactored with the following changes:
- Ensure constant in comparison is on the right [×2] (
flip-comparison
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
collate=" COLLATE {}".format(self.collate) if self.collate else "", | ||
collate=f" COLLATE {self.collate}" if self.collate else "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function JoinOn.get_sql
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
criterion_tables = set([f.table for f in self.criterion.fields_()]) | ||
criterion_tables = {f.table for f in self.criterion.fields_()} | ||
available_tables = set(_from) | {join.item for join in _joins} | {self.item} | ||
missing_tables = criterion_tables - available_tables | ||
if missing_tables: | ||
if missing_tables := criterion_tables - available_tables: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function JoinOn.validate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
if_not_exists = '' | ||
if self._if_not_exists: | ||
if_not_exists = 'IF NOT EXISTS ' | ||
|
||
if_not_exists = 'IF NOT EXISTS ' if self._if_not_exists else '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CreateQueryBuilder._create_table_sql
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace if statement with if expression (
assign-if-exp
)
clause += " ON DELETE " + self._foreign_key_on_delete.value | ||
clause += f" ON DELETE {self._foreign_key_on_delete.value}" | ||
if self._foreign_key_on_update: | ||
clause += " ON UPDATE " + self._foreign_key_on_update.value | ||
clause += f" ON UPDATE {self._foreign_key_on_update.value}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CreateQueryBuilder._foreign_key_clause
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
if isinstance(self._drop_target, Database): | ||
target_name = self._drop_target.get_sql(**kwargs) | ||
elif isinstance(self._drop_target, Table): | ||
if isinstance(self._drop_target, (Database, Table)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DropQueryBuilder.get_sql
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
) - Merge isinstance calls (
merge-isinstance
)
if value is None: | ||
return "null" | ||
return str(value) | ||
return "null" if value is None else str(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ValueWrapper.get_formatted_value
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
return "{}.*".format(format_quotes(namespace, quote_char)) | ||
return f"{format_quotes(namespace, quote_char)}.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Star.get_sql
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
sql = "[{}]".format(values) | ||
sql = f"[{values}]" | ||
if dialect in (Dialects.POSTGRESQL, Dialects.REDSHIFT): | ||
sql = "ARRAY[{}]".format(values) if len(values) > 0 else "'{}'" | ||
sql = f"ARRAY[{values}]" if values != "" else "'{}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Array.get_sql
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Simplify comparison to string length (
simplify-str-len-comparison
)
if with_alias: | ||
return format_alias_sql(sql, self.alias, **kwargs) | ||
return sql | ||
return format_alias_sql(sql, self.alias, **kwargs) if with_alias else sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BasicCriterion.get_sql
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if subcriterion: | ||
return "({criterion})".format(criterion=sql) | ||
|
||
return sql | ||
return "({criterion})".format(criterion=sql) if subcriterion else sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ComplexCriterion.get_sql
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
self._converter_options = converter_options or dict() | ||
self._converter_options = converter_options or {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Array.__init__
refactored with the following changes:
- Replace
dict()
with{}
(dict-literal
)
left='"%s"' % left if isinstance(self._left_array, Field) else left, | ||
right='"%s"' % right if isinstance(self._right_array, Field) else right, | ||
left=f'"{left}"' if isinstance(self._left_array, Field) else left, | ||
right=f'"{right}"' if isinstance(self._right_array, Field) else right, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function HasAny.get_sql
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
array='"%s"' % array if isinstance(self._array, Field) else array, | ||
array=f'"{array}"' if isinstance(self._array, Field) else array, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _AbstractArrayFunction.get_sql
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
patterns=",".join(["'%s'" % i for i in self._patterns]), | ||
patterns=",".join([f"'{i}'" for i in self._patterns]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _AbstractMultiSearchString.get_sql
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
field=self._field if isinstance(self._field, Field) else "'%s'" % str(self._field), | ||
field=self._field | ||
if isinstance(self._field, Field) | ||
else f"'{str(self._field)}'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ToFixedString.get_sql
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!