-
Notifications
You must be signed in to change notification settings - Fork 3
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
72 expressions improvements #117
Changes from 3 commits
eb0e438
0a6423f
62df4fa
2be2269
fd11302
5acd247
dae70a6
e89aa5f
2184d36
2136f91
e3b7cab
b587cec
6dc45d8
badad53
b1256f4
91d4d8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,15 +32,20 @@ def __new__(cls, *args, **kwargs): | |
class BaseModel(pyd.BaseModel, ABC): | ||
"""Mongreggate base class""" | ||
|
||
def to_expression(self)->dict: | ||
"""Converts an instance of a class inheriting from BaseModel to an expression""" | ||
|
||
return self.express(self) | ||
|
||
@classmethod | ||
def resolve(cls, obj:Any)->dict|list[dict]: | ||
def express(cls, obj:Any)->dict|list[dict]: | ||
"""Resolves an expression encapsulated in an object from a class inheriting from BaseModel""" | ||
|
||
return resolve(obj) | ||
return express(obj) | ||
|
||
@property | ||
@abstractmethod | ||
def statement(self)->dict: | ||
def expression(self)->dict: | ||
"""Stage statement absctract method""" | ||
|
||
# this is a lazy attribute | ||
|
@@ -49,7 +54,7 @@ def statement(self)->dict: | |
def __call__(self)->dict: | ||
"""Makes an instance of any class inheriting from this class callable""" | ||
|
||
return self.resolve(self.statement) | ||
return self.express(self.expression) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
|
||
class Config(pyd.BaseConfig): | ||
"""Base configuration for classes inheriting from this""" | ||
|
@@ -65,25 +70,25 @@ def isbasemodel(instance:Any)->TypeGuard[BaseModel]: | |
|
||
return isinstance(instance, BaseModel) | ||
|
||
def resolve(obj:Any)->dict|list[dict]: | ||
def express(obj:Any)->dict|list[dict]: | ||
"""Resolves an expression encapsulated in an object from a class inheriting from BaseModel""" | ||
|
||
if isbasemodel(obj): | ||
output:dict|list = obj.statement | ||
output:dict|list = obj.expression | ||
elif isinstance(obj, list) and any(map(isbasemodel, obj)): | ||
output = [] | ||
for element in obj: | ||
if isinstance(element, BaseModel): | ||
output.append(element.statement) | ||
output.append(element.expression) | ||
else: | ||
output.append(element) | ||
elif isinstance(obj, dict): | ||
output = {} | ||
for key, value in obj.items(): | ||
if isinstance(value, BaseModel): | ||
output[key] = value.statement | ||
output[key] = value.expression | ||
else: | ||
output[key] = resolve(value) | ||
output[key] = express(value) | ||
else: | ||
output = obj | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ class Average(Accumulator): | |
|
||
Attributes | ||
---------- | ||
expression : Any valid expression | ||
operand : Any valid expression | ||
|
||
Online MongoDB documentation: | ||
----------------------------- | ||
|
@@ -105,17 +105,17 @@ class Average(Accumulator): | |
expression : Any | ||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$avg" : self.expression | ||
}) | ||
|
||
Avg = Average | ||
|
||
def average(expression:Any)->Average: | ||
def average(operand:Any)->Average: | ||
"""Returns a $avg operator""" | ||
|
||
return Average(expression=expression) | ||
return Average(expression=operand) | ||
|
||
avg = average |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,13 +66,13 @@ | |
|
||
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/#mongodb-group-grp.-count) | ||
""" | ||
|
||
Check warning on line 69 in src/monggregate/operators/accumulators/count.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$count" : {} | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ | |
|
||
Attributes | ||
------------------------ | ||
- expression, Expression : Any valid expression | ||
- operand, Any : Any valid expression | ||
|
||
Online MongoDB documentation: | ||
------------------------------ | ||
|
@@ -88,13 +88,13 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/#mongodb-group-grp.-first) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 91 in src/monggregate/operators/accumulators/first.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$first" : self.expression | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ | |
|
||
Attributes | ||
------------------------ | ||
- expression, Expression : Any valid expression | ||
- operand, Any:Any valid expression | ||
|
||
Online MongoDB documentation | ||
---------------------------- | ||
|
@@ -80,18 +80,18 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/#mongodb-group-grp.-last) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 83 in src/monggregate/operators/accumulators/last.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$last" : self.expression | ||
}) | ||
|
||
def last(expression:Any)->Last: | ||
def last(operand:Any)->Last: | ||
"""Returns a $last operator""" | ||
|
||
return Last(expression=expression) | ||
return Last(expression=operand) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ | |
|
||
Attributes | ||
--------------------- | ||
- expression, Expression : Any valid expression | ||
- operand, Any:Any valid expression | ||
|
||
Online MongoDB documentation | ||
---------------------------- | ||
|
@@ -109,18 +109,18 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#mongodb-group-grp.-max) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 112 in src/monggregate/operators/accumulators/max.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$max" : self.expression | ||
}) | ||
|
||
def max(expression:Any)->Max: | ||
def max(operand:Any)->Max: | ||
"""Returns a $last operator""" | ||
|
||
return Max(expression=expression) | ||
return Max(expression=operand) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ | |
|
||
Attributes | ||
---------------------- | ||
- expression, Expression : Any valid expression | ||
- operand, Any:Any valid expression | ||
|
||
|
||
Online MongoDB documentation | ||
|
@@ -109,18 +109,18 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#mongodb-group-grp.-min) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 112 in src/monggregate/operators/accumulators/min.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$min" : self.expression | ||
}) | ||
|
||
def min(expression:Any)->Min: | ||
def min(operand:Any)->Min: | ||
"""Returns a $min operator""" | ||
|
||
return Min(expression=expression) | ||
return Min(expression=operand) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ | |
|
||
Attributes | ||
------------------- | ||
- expression, Expression : Any valid expression | ||
- operand, Any:Any valid expression | ||
|
||
Online MongoDB documentation | ||
---------------------------- | ||
|
@@ -52,18 +52,18 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/#mongodb-group-grp.-push) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 55 in src/monggregate/operators/accumulators/push.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$push" : self.expression | ||
}) | ||
|
||
def push(expression:Any)->Push: | ||
def push(operand:Any)->Push: | ||
"""Returns a $push operator""" | ||
|
||
return Push(expression=expression) | ||
return Push(expression=operand) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ | |
Attributes | ||
----------------------- | ||
- operands, list[Expression] : Any valid list of expressions | ||
- operand, Expression : Any valid expression | ||
- operand, Any :Any valid expression | ||
|
||
Online MongoDB documentation | ||
---------------------------- | ||
|
@@ -119,13 +119,13 @@ | |
[Source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum) | ||
""" | ||
|
||
expression : Any | ||
Check warning on line 122 in src/monggregate/operators/accumulators/sum.py GitHub Actions / lint-and-format-backend
|
||
|
||
|
||
@property | ||
def statement(self) -> dict: | ||
def expression(self) -> dict: | ||
|
||
return self.resolve({ | ||
return self.express({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
"$sum" : self.expression | ||
}) | ||
|
||
|
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.
🚫 [mypy] reported by reviewdog 🐶
Incompatible return value type (got "dict[Any, Any] | list[dict[Any, Any]]", expected "dict[Any, Any]") [return-value]