Skip to content
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

[BUG] Logical operators are not type compliant when using bool operations #1000

Open
dougsouza opened this issue Aug 15, 2024 · 1 comment
Open
Labels

Comments

@dougsouza
Copy link

Describe the bug
Logical operators are not type compliant when using bool operations (eg. Or(Product.price<10, Product.category=="Sweets"))

To Reproduce
Just use the same example from docs:

class Product(Document):
    price: float
    category: str

Or(Product.price<10, Product.category=="Sweets")

It seems that logical ops are missing bool in the accepted argument types: https://github.com/BeanieODM/beanie/blob/main/beanie/odm/operators/find/logical.py#L16

Expected behavior
Expected to work normally with type checking. Instead, got the error:

Argument 1 to "Or" has incompatible type "bool"; expected "BaseFindOperator | dict[str, Any] | Mapping[str, Any]"Mypy[arg-type](https://mypy.readthedocs.io/en/latest/_refs.html#code-arg-type)
Argument 2 to "Or" has incompatible type "bool"; expected "BaseFindOperator | dict[str, Any] | Mapping[str, Any]"Mypy[arg-type](https://mypy.readthedocs.io/en/latest/_refs.html#code-arg-type)

Regular find works ok with bool operations as it accepts bool as arg type:

def find(
    *args: Mapping[str, Any] | bool,
    ...
janas-adam added a commit to janas-adam/beanie that referenced this issue Sep 5, 2024
janas-adam added a commit to janas-adam/beanie that referenced this issue Sep 5, 2024
janas-adam added a commit to janas-adam/beanie that referenced this issue Sep 5, 2024
@janas-adam
Copy link

after mypy typing alerts i noticed that adding bool typing causing indexing errors in base class BaseOperator

        *expressions: Union[
            BaseFindOperator, Dict[str, Any], Mapping[str, Any], bool
        ],
    ):
        self.expressions = list(expressions)

    @property
    def query(self) -> Union[BaseFindOperator, Mapping[str, Any], bool]:

the thing why Nor & Not works is lack of typing in query property,
others which are not overridden ll have error

    @property
    def query(self):

what we can do for now without opening bunch of errors and to handle typing error is:
temporarily remove query typing in LogicalOperatorForListOfExpressions
and
then -> we can proceed with typing adjustment for all logical operators in a new issue with all specifications needed

fyi: here unified query typing for all logical operators #1021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants