Conversation
| relationship_info = RelationshipInfo( | ||
| return RelationshipInfo( | ||
| back_populates=back_populates, | ||
| link_model=link_model, | ||
| sa_relationship=sa_relationship, | ||
| sa_relationship_args=sa_relationship_args, | ||
| sa_relationship_kwargs=sa_relationship_kwargs, | ||
| ) | ||
| return relationship_info |
There was a problem hiding this comment.
Function Relationship refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| def __init__( | ||
| cls, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any | ||
| ) -> None: | ||
| def __init__(self, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any) -> None: |
There was a problem hiding this comment.
Function SQLModelMetaclass.__init__ refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
This removes the following comments ( why? ):
# Fix #315
| if issubclass(field.type_, BaseModel) and field.type_.__custom_root_type__: | ||
| return get_pydantic_root_model_engine_type( | ||
| get_sqlachemy_type(field.type_.__fields__["__root__"]), field.type_ | ||
| ) |
There was a problem hiding this comment.
Function get_sqlachemy_type refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| kwargs.update(cast(Dict[Any, Any], sa_column_kwargs)) | ||
| kwargs |= cast(Dict[Any, Any], sa_column_kwargs) |
There was a problem hiding this comment.
Function get_column_from_field refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| if getattr(self.__config__, "table", False): | ||
| if is_instrumented(self, name): | ||
| set_attribute(self, name, value) | ||
| if getattr(self.__config__, "table", False) and is_instrumented( | ||
| self, name | ||
| ): | ||
| set_attribute(self, name, value) |
There was a problem hiding this comment.
Function SQLModel.__setattr__ refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| if include is None and exclude is None and exclude_unset is False: | ||
| if include is None and exclude is None and not exclude_unset: |
There was a problem hiding this comment.
Function SQLModel._calculate_keys refactored with the following changes:
- Simplify comparison to boolean (
simplify-boolean-comparison) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# Do not include relationships as that would easily lead to infinite
# recursion, or traversing the whole database
# | self.__sqlmodel_relationships__.keys()
# Original in Pydantic:
# keys = self.__dict__.keys()
# Updated to not return SQLAlchemy attributes
| def __tablename__(cls) -> str: | ||
| return cls.__name__.lower() | ||
| def __tablename__(self) -> str: | ||
| return self.__name__.lower() |
There was a problem hiding this comment.
Function SQLModel.__tablename__ refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| sql_str = str(dialect).rstrip() | ||
| if sql_str: | ||
| print(sql_str + ";") | ||
| if sql_str := str(dialect).rstrip(): | ||
| print(f"{sql_str};") |
There was a problem hiding this comment.
Function pg_dump refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if sql_str: | ||
| print(sql_str + ";") | ||
| if sql_str := str(dialect).rstrip(): | ||
| print(f"{sql_str};") |
There was a problem hiding this comment.
Function sqlite_dump refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| str("Hero"), | ||
| float(0.5), | ||
| int(5), | ||
| datetime(year=2020, month=2, day=2, hour=2, minute=2, second=2, microsecond=2), | ||
| "Hero", | ||
| 0.5, | ||
| 5, | ||
| datetime( | ||
| year=2020, month=2, day=2, hour=2, minute=2, second=2, microsecond=2 | ||
| ), | ||
| date(year=2020, month=2, day=2), | ||
| timedelta( | ||
| days=2, seconds=2, microseconds=2, milliseconds=2, minutes=2, hours=2, weeks=2 | ||
| days=2, | ||
| seconds=2, | ||
| microseconds=2, | ||
| milliseconds=2, | ||
| minutes=2, | ||
| hours=2, | ||
| weeks=2, |
There was a problem hiding this comment.
Lines 20-26 refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool [×3] (
remove-unnecessary-cast)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.04%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Pull Request #2 refactored by Sourcery.
Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.
To incorporate these changes, you can either:
Merge this Pull Request instead of the original, or
Ask your contributor to locally incorporate these commits and push them to
the original Pull Request
Incorporate changes via command line
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Help us improve this pull request!