-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
# HTML table header | ||
html = '<table><tr><th>' | ||
html += '</th><th>'.join(columns) | ||
html = '<table><tr><th>' + '</th><th>'.join(columns) |
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 table_print
refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
)
This removes the following comments ( why? ):
# HTML table header
results = self._redis_conn.ft(self._name).search( # type: ignore | ||
return self._redis_conn.ft(self._name).search( # type: ignore | ||
*args, **kwargs | ||
) | ||
return results |
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 SearchIndex.search
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
results = await self._redis_conn.ft(self._name).search(*args, **kwargs) # type: ignore | ||
return results | ||
return await self._redis_conn.ft(self._name).search(*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 AsyncSearchIndex.search
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# type: ignore
for field in field_group: | ||
redis_fields.append(field.as_field()) | ||
redis_fields.extend(field.as_field() for field in field_group) |
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 SchemaModel.index_fields
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
field_class = field_classes.get(field_type) | ||
if field_class: | ||
if field_class := field_classes.get(field_type): |
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 SchemaGenerator.generate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
_filter = "*" | ||
if self._filter: | ||
_filter = str(self._filter) | ||
_filter = str(self._filter) if self._filter else "*" | ||
base_query = f"{_filter}=>[KNN {self._num_results} @{self._field} ${self.VECTOR_PARAM} AS {self.DISTANCE_ID}]" | ||
query = ( | ||
return ( | ||
Query(base_query) | ||
.return_fields(*self._return_fields) | ||
.sort_by(self.DISTANCE_ID) | ||
.paging(0, self._num_results) | ||
.dialect(2) | ||
) | ||
return query |
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 VectorQuery.query
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace if statement with if expression (
assign-if-exp
)
_filter = "*" | ||
if self._filter: | ||
_filter = str(self._filter) | ||
|
||
_filter = str(self._filter) if self._filter else "*" | ||
# Avoid appending a filter that yields '*' as it will cause a syntax error in Redis query language | ||
if _filter != "*": | ||
base_query = ( | ||
"(" | ||
+ base_query | ||
f"({base_query}" |
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 RangeQuery.query
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace if statement with if expression (
assign-if-exp
)
addr = os.getenv("REDIS_URL", None) | ||
if not addr: | ||
if addr := os.getenv("REDIS_URL", None): | ||
return addr | ||
else: | ||
raise ValueError("REDIS_URL env var not set") | ||
return addr |
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_address_from_env
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
)
if isinstance(data, tuple): | ||
return map(convert_bytes, data) | ||
return data | ||
return map(convert_bytes, data) if isinstance(data, tuple) else data |
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 convert_bytes
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 as_buffer: | ||
return array_to_buffer(embedding) | ||
return embedding | ||
return array_to_buffer(embedding) if as_buffer else embedding |
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 BaseVectorizer._process_embedding
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 len(texts) > 0 and not isinstance(texts[0], str): | ||
if texts and not isinstance(texts[0], str): |
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 HFTextVectorizer.embed_many
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
if len(texts) > 0 and not isinstance(texts[0], str): | ||
if texts and not isinstance(texts[0], str): |
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 OpenAITextVectorizer.embed_many
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
if len(texts) > 0 and not isinstance(texts[0], str): | ||
if texts and not isinstance(texts[0], str): |
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 OpenAITextVectorizer.aembed_many
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
if len(texts) > 0 and not isinstance(texts[0], str): | ||
if texts and not isinstance(texts[0], str): |
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 VertexAITextVectorizer.embed_many
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
assert int(doc.age) in [18, 14, 94, 100, 12, 15, 35] | ||
assert int(doc.age) in {18, 14, 94, 100, 12, 15, 35} |
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_simple
refactored with the following changes:
- Use set when checking membership of a collection of literals (
collection-into-set
)
users = [doc for doc in results.docs] | ||
users = list(results.docs) |
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_simple
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
tag = Tag("tag_field") == None | ||
tag = Tag("tag_field") is 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 test_nullable
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
nf = Num("numeric_field") == None | ||
nf = Num("numeric_field") is 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 test_numeric_filter
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
tf1 = Tag("tag_field") == None | ||
tf1 = Tag("tag_field") is None | ||
tf2 = Tag("tag_field") == "" | ||
assert str(tf1 & tf2) == "*" | ||
|
||
tf1 = Tag("tag_field") == None | ||
tf1 = Tag("tag_field") is None | ||
tf2 = Tag("tag_field") == "tag" | ||
assert str(tf1 & tf2) == str(tf2) | ||
|
||
tf1 = Tag("tag_field") == None | ||
tf1 = Tag("tag_field") is None | ||
tf2 = Tag("tag_field") == ["tag1", "tag2"] | ||
assert str(tf1 & tf2) == str(tf2) | ||
|
||
tf1 = Tag("tag_field") == None | ||
tf1 = Tag("tag_field") is 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 test_filters_combination
refactored with the following changes:
- Use x is None rather than x == None [×10] (
none-compare
)
instance = StorageClass(prefix="test", key_separator=":") | ||
return instance | ||
return StorageClass(prefix="test", key_separator=":") |
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 storage_instance
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Hello @sourcery-ai[bot]! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:
|
Branch
main
refactored 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
main
branch, then run:Help us improve this pull request!