Skip to content

Commit

Permalink
Replaced dict typehint by Expression in operators
Browse files Browse the repository at this point in the history
  • Loading branch information
VianneyMI committed Apr 21, 2024
1 parent 2184d36 commit 2136f91
Show file tree
Hide file tree
Showing 47 changed files with 98 additions and 62 deletions.
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@


from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Average(Accumulator):
Expand Down Expand Up @@ -105,7 +106,7 @@ class Average(Accumulator):
operand : Any

@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$avg" : self.operand
Expand Down
4 changes: 2 additions & 2 deletions src/monggregate/operators/accumulators/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"""


from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Count(Accumulator):
Expand All @@ -70,7 +70,7 @@ class Count(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$count" : {}
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/first.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@


from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class First(Accumulator):
Expand Down Expand Up @@ -92,7 +93,7 @@ class First(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$first" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/last.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@


from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Last(Accumulator):
Expand Down Expand Up @@ -85,7 +86,7 @@ class Last(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$last" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/max.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@


from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Max(Accumulator):
Expand Down Expand Up @@ -114,7 +115,7 @@ class Max(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$max" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/min.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Min(Accumulator):
Expand Down Expand Up @@ -114,7 +115,7 @@ class Min(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$min" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Push(Accumulator):
Expand Down Expand Up @@ -57,7 +58,7 @@ class Push(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$push" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/accumulators/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.accumulators.accumulator import Accumulator

class Sum(Accumulator):
Expand Down Expand Up @@ -123,7 +124,7 @@ class Sum(Accumulator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:

return self.express({
"$sum" : self.operand
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/arithmetic/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.arithmetic.arithmetic import ArithmeticOperator

class Add(ArithmeticOperator):
Expand Down Expand Up @@ -53,7 +54,7 @@ class Add(ArithmeticOperator):
operands : list[Any]

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$add" : self.operands
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/arithmetic/divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.arithmetic.arithmetic import ArithmeticOperator

class Divide(ArithmeticOperator):
Expand Down Expand Up @@ -57,7 +58,7 @@ class Divide(ArithmeticOperator):
denominator : Any

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$divide" : [self.numerator, self.denominator]
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/arithmetic/multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.arithmetic.arithmetic import ArithmeticOperator

class Multiply(ArithmeticOperator):
Expand Down Expand Up @@ -52,7 +53,7 @@ class Multiply(ArithmeticOperator):
operands : list[Any]

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$multiply" : self.operands
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/arithmetic/pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.arithmetic.arithmetic import ArithmeticOperator

class Pow(ArithmeticOperator):
Expand Down Expand Up @@ -73,7 +74,7 @@ class Pow(ArithmeticOperator):
exponent : Any

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$pow" : [self.number, self.exponent]
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/arithmetic/subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.arithmetic.arithmetic import ArithmeticOperator

class Subtract(ArithmeticOperator):
Expand Down Expand Up @@ -73,7 +74,7 @@ class Subtract(ArithmeticOperator):
right: Any

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$substract" : [self.left, self.right]
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/array_to_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOperator

class ArrayToObject(ArrayOperator):
Expand Down Expand Up @@ -92,7 +93,7 @@ class ArrayToObject(ArrayOperator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$arrayToObject" : self.operand
})
Expand Down
4 changes: 2 additions & 2 deletions src/monggregate/operators/array/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"""

from typing import Any
from monggregate.base import pyd
from monggregate.base import pyd, Expression
from monggregate.operators.array.array import ArrayOperator

class Filter(ArrayOperator):
Expand Down Expand Up @@ -110,7 +110,7 @@ class Filter(ArrayOperator):
limit : int | None = pyd.Field(None, ge=1) # NOTE : limit can actually be an expression but constraints are invalid with any type

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$filter":{
"input" : self.operand,
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/first.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOnlyOperator

class First(ArrayOnlyOperator):
Expand All @@ -116,7 +117,7 @@ class First(ArrayOnlyOperator):
"""

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$first":self.operand
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/in_.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOperator

class In(ArrayOperator):
Expand Down Expand Up @@ -65,7 +66,7 @@ class In(ArrayOperator):


@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$in":[self.left, self.right]
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/is_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOnlyOperator

class IsArray(ArrayOnlyOperator):
Expand All @@ -47,7 +48,7 @@ class IsArray(ArrayOnlyOperator):
"""

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$isArray":self.operand
})
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/last.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOnlyOperator

class Last(ArrayOnlyOperator):
Expand All @@ -126,7 +127,7 @@ class Last(ArrayOnlyOperator):
"""

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$last":self.operand
})
Expand Down
4 changes: 2 additions & 2 deletions src/monggregate/operators/array/max_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"""

from typing import Any
from monggregate.base import pyd
from monggregate.base import pyd, Expression
from monggregate.operators.array.array import ArrayOperator

class MaxN(ArrayOperator):
Expand All @@ -70,7 +70,7 @@ class MaxN(ArrayOperator):
limit : Any = pyd.Field(1, alias="n")

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$maxN" : {
"n" : self.limit,
Expand Down
4 changes: 2 additions & 2 deletions src/monggregate/operators/array/min_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"""

from typing import Any
from monggregate.base import pyd
from monggregate.base import pyd, Expression
from monggregate.operators.array.array import ArrayOperator

class MinN(ArrayOperator):
Expand All @@ -69,7 +69,7 @@ class MinN(ArrayOperator):
limit : Any = pyd.Field(1, alias="n")

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$minN" : {
"n" : self.limit,
Expand Down
3 changes: 2 additions & 1 deletion src/monggregate/operators/array/size.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""

from typing import Any
from monggregate.base import Expression
from monggregate.operators.array.array import ArrayOnlyOperator

class Size(ArrayOnlyOperator):
Expand All @@ -54,7 +55,7 @@ class Size(ArrayOnlyOperator):
"""

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$size":self.operand
})
Expand Down
4 changes: 2 additions & 2 deletions src/monggregate/operators/array/sort_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

from typing import Any, Literal

from monggregate.base import pyd
from monggregate.base import pyd, Expression
from monggregate.operators.array.array import ArrayOperator

class SortArray(ArrayOperator):
Expand Down Expand Up @@ -123,7 +123,7 @@ class SortArray(ArrayOperator):
by : dict[str, Literal[1, -1]] = pyd.Field(1, alias="sort_by")

@property
def expression(self) -> dict:
def expression(self) -> Expression:
return self.express({
"$sortArray":{
"input" : self.operand,
Expand Down
Loading

0 comments on commit 2136f91

Please sign in to comment.