Conversation
| encoded_list = [] | ||
| for item in obj: | ||
| encoded_list.append( | ||
| jsonable_encoder( | ||
| item, | ||
| include=include, | ||
| exclude=exclude, | ||
| by_alias=by_alias, | ||
| exclude_unset=exclude_unset, | ||
| exclude_defaults=exclude_defaults, | ||
| exclude_none=exclude_none, | ||
| custom_encoder=custom_encoder, | ||
| sqlalchemy_safe=sqlalchemy_safe, | ||
| ) | ||
| return [ | ||
| jsonable_encoder( | ||
| item, | ||
| include=include, | ||
| exclude=exclude, | ||
| by_alias=by_alias, | ||
| exclude_unset=exclude_unset, | ||
| exclude_defaults=exclude_defaults, | ||
| exclude_none=exclude_none, | ||
| custom_encoder=custom_encoder, | ||
| sqlalchemy_safe=sqlalchemy_safe, | ||
| ) | ||
| return encoded_list | ||
|
|
||
| for item in obj | ||
| ] | ||
| if custom_encoder: | ||
| if type(obj) in custom_encoder: | ||
| return custom_encoder[type(obj)](obj) | ||
| else: | ||
| for encoder_type, encoder in custom_encoder.items(): | ||
| if isinstance(obj, encoder_type): | ||
| return encoder(obj) | ||
| for encoder_type, encoder in custom_encoder.items(): | ||
| if isinstance(obj, encoder_type): | ||
| return encoder(obj) |
There was a problem hiding this comment.
Function jsonable_encoder refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| err_loc_tree = [str(loc_part) for loc_part in e["loc"]] | ||
| target = ".".join(err_loc_tree) | ||
| return target | ||
| return ".".join(err_loc_tree) |
There was a problem hiding this comment.
Function get_validation_target refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| def with_params(self, params: BaseModel): | ||
| return create_model("JsonRPC" + params.__name__, __base__=self, params=(params, ...)) | ||
| def with_params(cls, params: BaseModel): | ||
| return create_model( | ||
| f"JsonRPC{params.__name__}", __base__=cls, params=(params, ...) | ||
| ) |
There was a problem hiding this comment.
Function JsonRPCRequest.with_params refactored with the following changes:
- The first argument to class methods should be
cls(class-method-first-arg-name) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| reply_name = "Reply_" + self.operation_id | ||
| request_name = "Request_" + self.operation_id | ||
| reply_name = f"Reply_{self.operation_id}" | ||
| request_name = f"Request_{self.operation_id}" |
There was a problem hiding this comment.
Function Request.__init__ refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| self.operation_id = generate_operation_id_for_subject(summary=self.summary, subject=self.subject) | ||
| self.params = get_request_model(self.endpoint, subject, self.skip_validation) | ||
| reply_name = "Reply_" + self.operation_id | ||
| reply_name = f"Reply_{self.operation_id}" |
There was a problem hiding this comment.
Function Publish.__init__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| schema = {} | ||
| schema["range"] = {"upper": upper_bound, "lower": lower_bound} | ||
| schema = {"range": {"upper": upper_bound, "lower": lower_bound}} |
There was a problem hiding this comment.
Function domain_errors_schema refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| info = {"title": title, "version": version} | ||
| info["description"] = description if description else None | ||
| info = { | ||
| "title": title, | ||
| "version": version, | ||
| "description": description if description else None, | ||
| } |
There was a problem hiding this comment.
Function get_asyncapi refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Simplify sequence length comparison (
simplify-len-comparison)
| reply_raw = await self.nats.request(subject, json_rpc_payload.json().encode(), timeout, headers=headers) | ||
| reply = JsonRPCReply.parse_raw(reply_raw.data) | ||
| return reply | ||
| return JsonRPCReply.parse_raw(reply_raw.data) |
There was a problem hiding this comment.
Function NatsClient.request refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| asyncio.create_task(self._handle_request(msg), name="natsapi_" + secrets.token_hex(16)) | ||
| asyncio.create_task( | ||
| self._handle_request(msg), name=f"natsapi_{secrets.token_hex(16)}" | ||
| ) | ||
| else: | ||
| asyncio.create_task(self._handle_publish(msg), name="natsapi_" + secrets.token_hex(16)) | ||
| asyncio.create_task( | ||
| self._handle_publish(msg), name=f"natsapi_{secrets.token_hex(16)}" | ||
| ) |
There was a problem hiding this comment.
Function NatsClient.handle_request refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| for cls in type(exc).__mro__: | ||
| if cls in self._exception_handlers: | ||
| return self._exception_handlers[cls] | ||
| return None | ||
| return next( | ||
| ( | ||
| self._exception_handlers[cls] | ||
| for cls in type(exc).__mro__ | ||
| if cls in self._exception_handlers | ||
| ), | ||
| None, | ||
| ) |
There was a problem hiding this comment.
Function NatsClient._lookup_exception_handler refactored with the following changes:
- Use the built-in function
nextinstead of a for-loop (use-next)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!