-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #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
base: main
Are you sure you want to change the base?
Conversation
| use_pr: Optional[PullRequest] = None | ||
| for pr in repo.get_pulls(): | ||
| if pr.head.sha == event.workflow_run.head_commit.id: | ||
| use_pr = pr | ||
| break | ||
| use_pr: Optional[PullRequest] = next( | ||
| ( | ||
| pr | ||
| for pr in repo.get_pulls() | ||
| if pr.head.sha == event.workflow_run.head_commit.id | ||
| ), | ||
| None, | ||
| ) | ||
|
|
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.
Lines 45-49 refactored with the following changes:
- Use the built-in function
nextinstead of a for-loop (use-next)
| notified = False | ||
| for pr_comment in pr_comments: | ||
| if message in pr_comment.body: | ||
| notified = True | ||
| notified = any(message in pr_comment.body for pr_comment in pr_comments) | ||
| logging.info(f"Docs preview was notified: {notified}") | ||
| if not notified: | ||
| artifact_name = f"docs-zip-{commit}" | ||
| use_artifact: Optional[Artifact] = None | ||
| for artifact in artifacts_response.artifacts: | ||
| if artifact.name == artifact_name: | ||
| use_artifact = artifact | ||
| break | ||
| use_artifact: Optional[Artifact] = next( | ||
| ( | ||
| artifact | ||
| for artifact in artifacts_response.artifacts | ||
| if artifact.name == artifact_name | ||
| ), | ||
| None, | ||
| ) | ||
|
|
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.
| ): | ||
| heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() | ||
| return heroes | ||
| return session.exec(select(Hero).offset(offset).limit(limit)).all() |
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 read_heroes refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| with Session(engine) as session: | ||
| heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() | ||
| return heroes | ||
| return session.exec(select(Hero).offset(offset).limit(limit)).all() |
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 read_heroes refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| with Session(engine) as session: | ||
| heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() | ||
| return heroes | ||
| return session.exec(select(Hero).offset(offset).limit(limit)).all() |
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 read_heroes refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| with Session(engine) as session: | ||
| heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() | ||
| return heroes | ||
| return session.exec(select(Hero).offset(offset).limit(limit)).all() |
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 read_heroes refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
| foreign_key = getattr(field.field_info, "foreign_key", None) | ||
| if foreign_key: | ||
| if foreign_key := getattr(field.field_info, "foreign_key", None): |
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 get_column_from_field refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SQLModel.__setattr__ refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.80%.
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! |
| if not getattr(cls.__config__, "table", False): | ||
| # If not table, normal Pydantic code | ||
| m: _TSQLModel = cls.__new__(cls) | ||
| else: | ||
| # If table, create the new instance normally to make SQLAlchemy create | ||
| # the _sa_instance_state attribute | ||
| m = cls() | ||
| m = cls() if getattr(cls.__config__, "table", False) else cls.__new__(cls) |
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 SQLModel.from_orm refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# the _sa_instance_state attribute
# If table, create the new instance normally to make SQLAlchemy create
# If not table, normal Pydantic code
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? ):
# Updated to not return SQLAlchemy attributes
# recursion, or traversing the whole database
# Original in Pydantic:
# | self.__sqlmodel_relationships__.keys()
# keys = self.__dict__.keys()
# Do not include relationships as that would easily lead to infinite
| def __tablename__(cls) -> str: | ||
| return cls.__name__.lower() | ||
| def __tablename__(self) -> str: | ||
| return self.__name__.lower() |
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 SQLModel.__tablename__ refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| if not isinstance(query_cache_size, _DefaultPlaceholder): | ||
| current_kwargs["query_cache_size"] = query_cache_size | ||
| current_kwargs.update(kwargs) | ||
| current_kwargs |= kwargs |
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 create_engine refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| if not isinstance(value, uuid.UUID): | ||
| return f"{uuid.UUID(value).int:x}" | ||
| else: | ||
| # hexstring | ||
| return f"{value.int:x}" | ||
| return ( | ||
| f"{value.int:x}" | ||
| if isinstance(value, uuid.UUID) | ||
| else f"{uuid.UUID(value).int:x}" | ||
| ) |
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 GUID.process_bind_param refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# hexstring
| value2 = Default("bar") | ||
|
|
||
| assert not (value1 == value2) | ||
| assert value1 != value2 |
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 test_not_equality refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| value2 = "foo" | ||
|
|
||
| assert not (value1 == value2) | ||
| assert value1 != "foo" |
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 test_not_equality_other refactored with the following changes:
- Inline variable that is only used once (
inline-variable) - Simplify logical expression using De Morgan identities (
de-morgan)
| # Now that this item was checked, remove it from the list | ||
| calls.pop(calls.index(call)) | ||
| assert len(calls) == 0, "The list should only have the expected items" | ||
| assert not calls, "The list should only have the expected items" |
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 test_tutorial refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| # Now that this item was checked, remove it from the list | ||
| calls.pop(calls.index(call)) | ||
| assert len(calls) == 0, "The list should only have the expected items" | ||
| assert not calls, "The list should only have the expected items" |
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 test_tutorial refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| # Now that this item was checked, remove it from the list | ||
| calls.pop(calls.index(call)) | ||
| assert len(calls) == 0, "The list should only have the expected items" | ||
| assert not calls, "The list should only have the expected items" |
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 test_tutorial refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
perf: raise exception if no matching sqlalchemy type
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!