-
Couldn't load subscription status.
- Fork 9
Simulation (Sourcery refactored) #5
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: simulation
Are you sure you want to change the base?
Conversation
60cd7e0 to
eb61e24
Compare
eb61e24 to
01244a8
Compare
| results = self._adapted.select( | ||
| yield from self._adapted.select( | ||
| session, | ||
| conditions=filters, | ||
| options=[sa.orm.selectinload(getattr(self.model, attr)) for attr in join_list], | ||
| options=[ | ||
| sa.orm.selectinload(getattr(self.model, attr)) | ||
| for attr in join_list | ||
| ], | ||
| include_inactive=allow_inactive, | ||
| yield_by_chunk=chunk_size, | ||
| ) | ||
| for result in results: | ||
| yield result |
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 RepositoryLegacyAdapter.yield_by_chunk refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable) - Replace yield inside for loop with yield from (
yield-from)
| if sqla_model: | ||
| return result | ||
| return self.model_schema.from_orm(result) | ||
| return result if sqla_model else self.model_schema.from_orm(result) |
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 insert 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 sqla_model: | ||
| return existing | ||
| return self.model_schema.from_orm(existing) | ||
| return existing if sqla_model else self.model_schema.from_orm(existing) |
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 update 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 sqla_model: | ||
| return row | ||
| return self.model_schema.from_orm(row) | ||
| return row if sqla_model else self.model_schema.from_orm(row) |
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 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 error_code: | ||
| return "failed" | ||
| return "ok" | ||
| return "failed" if (error_code := values.get("error_code")) else "ok" |
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 ResponseWrapper.set_status_by_error_code refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
|
|
||
| def __hash__(self): | ||
| return hash(tuple([self._encoded_id, self._decoded_id])) | ||
| return hash((self._encoded_id, self._decoded_id)) |
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 ObjectID.__hash__ refactored with the following changes:
- Unwrap a constant iterable constructor (
unwrap-iterable-construction)
| return value | ||
| else: | ||
| return self.hashids.decode(value)[0] | ||
| return value if isinstance(value, int) else self.hashids.decode(value)[0] |
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 ObjectID._decode refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| db = QuartSQLAlchemy(app=app) | ||
|
|
||
| yield db | ||
| yield QuartSQLAlchemy(app=app) |
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 SimpleTestBase.db refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable)
| db = QuartSQLAlchemy(app=app) | ||
|
|
||
| yield db | ||
| yield QuartSQLAlchemy(app=app) |
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 MixinTestBase.db refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable)
01244a8 to
c05116a
Compare
| else: | ||
| bind = Bind.get_instance(bind_name) | ||
| bind = Bind.get_instance(bind_name) | ||
|
|
||
| with create_session(bind) as session: | ||
| return func(*args, session=session, **kwargs) | ||
| with create_session(bind) as session: | ||
| return func(*args, session=session, **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 provide_session refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| dto = self._session.scalars(self._query.filter_by(uuid=entity_id)).one_or_none() | ||
| if not dto: | ||
| if dto := self._session.scalars( | ||
| self._query.filter_by(uuid=entity_id) | ||
| ).one_or_none(): | ||
| return Entity(dto) | ||
| else: | ||
| raise NotFound(entity_id) | ||
| return Entity(dto) |
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 ORMRepository.get refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Swap if/else branches (
swap-if-else-branches)
| execute_options = values["execution_options"].dict(exclude_defaults=True) | ||
| if execute_options: | ||
| if execute_options := values["execution_options"].dict( | ||
| exclude_defaults=True | ||
| ): |
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 EngineConfig.scrub_execution_options refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| [isinstance(arg, (sa.orm.Session, sa.ext.asyncio.AsyncSession)) for arg in args] | ||
| isinstance(arg, (sa.orm.Session, sa.ext.asyncio.AsyncSession)) | ||
| for arg in args | ||
| ) | ||
| session_in_kwargs = "session" in kwargs | ||
| session_provided = session_in_args or session_in_kwargs | ||
|
|
||
| if session_provided: | ||
| return func(self, *args, **kwargs) | ||
| else: | ||
| session = session_proxy() | ||
| session = session_proxy() | ||
|
|
||
| return func(self, session, *args, **kwargs) | ||
| return func(self, session, *args, **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 provide_global_contextual_session refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| app: t.Optional[Quart] = None, | ||
| ): | ||
| initialize = False if config is None else True | ||
| initialize = config is not 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 QuartSQLAlchemy.__init__ refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| "User duplication for email: {} (client_id: {})".format( | ||
| email, | ||
| client_id, | ||
| ), | ||
| f"User duplication for email: {email} (client_id: {client_id})" |
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 AuthUser.add_by_email_and_client_id refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| "New auth user (id: {}) created by (client_id: {})".format(row.id, client_id), | ||
| f"New auth user (id: {row.id}) created by (client_id: {client_id})" |
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 AuthUser.add_by_client_id refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| new_row = self._repository.add( | ||
| return self._repository.add( |
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 AuthWallet.add refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if not row: | ||
| return None | ||
|
|
||
| return one(row) | ||
| return one(row) if row else 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 AuthWallet.get_by_public_address 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) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| if not rows: | ||
| return [] | ||
|
|
||
| return rows | ||
| return rows 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 AuthWallet.get_by_auth_user_id 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) - Swap if/else branches of if expression to remove negation (
swap-if-expression) - Simplify if expression by using or (
or-if-exp-identity)
| else: | ||
| order_by_clause = () | ||
|
|
||
| order_by_clause = (order_by_clause, ) if order_by_clause is not None 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 RepositoryLegacyAdapter.get_by refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| for group in group_by: | ||
| selectables.append(group.expression) | ||
|
|
||
| selectables.extend(group.expression for group in group_by) |
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 RepositoryLegacyAdapter.count_by refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend)
| results = self._adapted.select( | ||
| yield from self._adapted.select( | ||
| session, | ||
| conditions=filters, | ||
| options=[sa.orm.selectinload(getattr(self.model, attr)) for attr in join_list], | ||
| options=[ | ||
| sa.orm.selectinload(getattr(self.model, attr)) | ||
| for attr in join_list | ||
| ], | ||
| include_inactive=allow_inactive, | ||
| yield_by_chunk=chunk_size, | ||
| ) | ||
| for result in results: | ||
| yield result |
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 RepositoryLegacyAdapter.yield_by_chunk refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable) - Replace yield inside for loop with yield from (
yield-from)
| if sqla_model: | ||
| return result | ||
| return self.model_schema.from_orm(result) | ||
| return result if sqla_model else self.model_schema.from_orm(result) |
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 insert 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 sqla_model: | ||
| return existing | ||
| return self.model_schema.from_orm(existing) | ||
| return existing if sqla_model else self.model_schema.from_orm(existing) |
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 update 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 error_code: | ||
| return "failed" | ||
| return "ok" | ||
| return "failed" if (error_code := values.get("error_code")) else "ok" |
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 ResponseWrapper.set_status_by_error_code refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
|
|
||
| def __hash__(self): | ||
| return hash(tuple([self._encoded_id, self._decoded_id])) | ||
| return hash((self._encoded_id, self._decoded_id)) |
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 ObjectID.__hash__ refactored with the following changes:
- Unwrap a constant iterable constructor (
unwrap-iterable-construction)
| return value | ||
| else: | ||
| return self.hashids.decode(value)[0] | ||
| return value if isinstance(value, int) else self.hashids.decode(value)[0] |
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 ObjectID._decode refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| db = QuartSQLAlchemy(app=app) | ||
|
|
||
| yield db | ||
| yield QuartSQLAlchemy(app=app) |
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 SimpleTestBase.db refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable)
| db = QuartSQLAlchemy(app=app) | ||
|
|
||
| yield db | ||
| yield QuartSQLAlchemy(app=app) |
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 MixinTestBase.db refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable)
Pull Request #4 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
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:
Review changes via command line
To manually merge these changes, make sure you're on the
simulationbranch, then run:Help us improve this pull request!