Sourcery refactored main branch#2
Conversation
|
|
||
| sentry_dsn = os.getenv("SENTRY_DSN") | ||
| if sentry_dsn: | ||
| if sentry_dsn := os.getenv("SENTRY_DSN"): |
There was a problem hiding this comment.
Lines 23-24 refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| tmp_file_name = "tmp-file-" + file_name | ||
| tmp_file_name = f"tmp-file-{file_name}" |
There was a problem hiding this comment.
Function process_file_and_notify refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| missing_vars = [var for var in required_vars if not os.getenv(var)] | ||
|
|
||
| if missing_vars: | ||
| if missing_vars := [var for var in required_vars if not os.getenv(var)]: |
There was a problem hiding this comment.
Function verify_env_variables refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| API_KEY = os.getenv("CI_TEST_API_KEY") | ||
| if not API_KEY: | ||
| if API_KEY := os.getenv("CI_TEST_API_KEY"): | ||
| return API_KEY | ||
| else: | ||
| raise ValueError( | ||
| "CI_TEST_API_KEY environment variable not set. Cannot run tests." | ||
| ) | ||
| return API_KEY |
There was a problem hiding this comment.
Function api_key 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)
|
|
||
| sentry_dsn = os.getenv("SENTRY_DSN") | ||
| if sentry_dsn: | ||
| if sentry_dsn := os.getenv("SENTRY_DSN"): |
There was a problem hiding this comment.
Lines 40-41 refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| headers = {} | ||
|
|
There was a problem hiding this comment.
Function get_api_call_response_as_text refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Convert for loop into dictionary comprehension (
dict-comprehension)
| sanitized_string = re.sub(r"[^a-zA-Z0-9_-]", "", string) | ||
|
|
||
| return sanitized_string | ||
| return re.sub(r"[^a-zA-Z0-9_-]", "", string) |
There was a problem hiding this comment.
Function sanitize_function_name refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| to_encode.update({"exp": expire}) | ||
| encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | ||
| return encoded_jwt | ||
| to_encode["exp"] = expire | ||
| return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) |
There was a problem hiding this comment.
Function create_access_token refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| return False | ||
|
|
||
| return True | ||
| return len(self.vectors_ids) != 0 |
There was a problem hiding this comment.
Function File.file_already_exists 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) - Simplify boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
This removes the following comments ( why? ):
# pyright: ignore reportPrivateUsage=none
| if len(response.data) == 0: | ||
| return False | ||
|
|
||
| return True | ||
| return len(response.data) != 0 |
There was a problem hiding this comment.
Function File.file_already_exists_in_brain 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) - Simplify boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| if settings.ollama_api_base_url: | ||
| embeddings = OllamaEmbeddings( | ||
| return ( | ||
| OllamaEmbeddings( | ||
| base_url=settings.ollama_api_base_url, | ||
| ) # pyright: ignore reportPrivateUsage=none | ||
| else: | ||
| embeddings = OpenAIEmbeddings() # pyright: ignore reportPrivateUsage=none | ||
| return embeddings | ||
| ) | ||
| if settings.ollama_api_base_url | ||
| else OpenAIEmbeddings() | ||
| ) |
There was a problem hiding this comment.
Function get_embeddings refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| documents_vector_store = SupabaseVectorStore( | ||
| return SupabaseVectorStore( | ||
| supabase_client, embeddings, table_name="vectors" | ||
| ) | ||
| return documents_vector_store |
There was a problem hiding this comment.
Function get_documents_vector_store refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| request = self.supabase_db.get_user_usage(self.id) | ||
|
|
||
| return request | ||
| return self.supabase_db.get_user_usage(self.id) |
There was a problem hiding this comment.
Function UserUsage.get_user_usage refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| request = self.supabase_db.get_model_settings() | ||
|
|
||
| return request | ||
| return self.supabase_db.get_model_settings() |
There was a problem hiding this comment.
Function UserUsage.get_model_settings refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| response = ( | ||
| return ( | ||
| self.db.table("brain_subscription_invitations") | ||
| .select("*") | ||
| .eq("brain_id", str(brain_id)) | ||
| .eq("email", user_email) | ||
| .execute() | ||
| ) | ||
|
|
||
| return response |
There was a problem hiding this comment.
Function BrainSubscription.get_subscription_invitations_by_brain_id_and_email refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| response = ( | ||
| return ( | ||
| self.db.table("api_keys") | ||
| .select("user_id") | ||
| .filter("api_key", "eq", api_key) | ||
| .execute() | ||
| ) | ||
| return response |
There was a problem hiding this comment.
Function ApiKeys.get_user_id_by_api_key refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| headers={ | ||
| "Authorization": "Bearer " + api_key, | ||
| }, | ||
| "/api-key", headers={"Authorization": f"Bearer {api_key}"} |
There was a problem hiding this comment.
Function test_create_and_delete_api_key refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if response.data == []: | ||
| return None | ||
| return BrainEntity(**response.data[0]) | ||
| return None if response.data == [] else BrainEntity(**response.data[0]) |
There was a problem hiding this comment.
Function Brains.get_brain_details 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)
| results = ( | ||
| self.db.table("brains").delete().match({"brain_id": brain_id}).execute() | ||
| return ( | ||
| self.db.table("brains") | ||
| .delete() | ||
| .match({"brain_id": brain_id}) | ||
| .execute() | ||
| ) | ||
|
|
||
| return results |
There was a problem hiding this comment.
Function Brains.delete_brain refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if len(response) == 0: | ||
| return None | ||
|
|
||
| return BrainEntity(**response[0]) | ||
| return None if len(response) == 0 else BrainEntity(**response[0]) |
There was a problem hiding this comment.
Function Brains.get_brain_by_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)
| results = ( | ||
| return ( | ||
| self.db.table("brains_users") | ||
| .delete() | ||
| .match({"brain_id": brain_id}) | ||
| .execute() | ||
| ) | ||
|
|
||
| return results |
There was a problem hiding this comment.
Function BrainsUsers.delete_brain_users refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| response = ( | ||
| return ( |
There was a problem hiding this comment.
Function BrainsUsers.create_brain_user refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if len(response) == 0: | ||
| return None | ||
| return UUID(response[0].get("brain_id")) | ||
| return None if len(response) == 0 else UUID(response[0].get("brain_id")) |
There was a problem hiding this comment.
Function BrainsUsers.get_user_default_brain_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)
| results = ( | ||
| return ( | ||
| self.db.table("brains_users") | ||
| .delete() | ||
| .match({"brain_id": str(brain_id)}) | ||
| .match({"rights": "Viewer"}) | ||
| .execute() | ||
| ).data | ||
|
|
||
| return results |
There was a problem hiding this comment.
Function BrainsUsers.delete_brain_subscribers refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| return [] | ||
|
|
||
| return vector_ids | ||
| return [] if not vector_ids else vector_ids |
There was a problem hiding this comment.
Function BrainsVectors.get_brain_vector_ids 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) - Simplify sequence length comparison (
simplify-len-comparison)
| "/brains/", | ||
| headers={"Authorization": "Bearer " + api_key}, | ||
| "/brains/", headers={"Authorization": f"Bearer {api_key}"} |
There was a problem hiding this comment.
Function test_delete_all_brains refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| "/brains/", | ||
| headers={"Authorization": "Bearer " + api_key}, | ||
| "/brains/", headers={"Authorization": f"Bearer {api_key}"} |
There was a problem hiding this comment.
Function test_delete_all_brains_and_get_default_brain refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| headers={"Authorization": "Bearer " + api_key}, | ||
| headers={"Authorization": f"Bearer {api_key}"}, |
There was a problem hiding this comment.
Function test_set_as_default_brain_endpoint refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| headers={"Authorization": "Bearer " + api_key}, | ||
| headers={"Authorization": f"Bearer {api_key}"}, |
There was a problem hiding this comment.
Function create_public_brain_retrieve_and_then_delete refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| if brain_id: | ||
| brain = brain_service.get_brain_by_id(brain_id) | ||
| if brain: | ||
| if brain := brain_service.get_brain_by_id(brain_id): |
There was a problem hiding this comment.
Function create_question_handler refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
Apply Sweep Rules to your PR?
This is an automated message generated by Sweep AI. |
|


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!