BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.99k stars 211 forks source link

[BUG] pylance for set inc and delete method (function #709

Open CAPITAINMARVEL opened 11 months ago

CAPITAINMARVEL commented 11 months ago

Describe the bug

So im trying update a document using set (for a boolean and i have this error pylance : Unable to assign argument of type “dict[bool, bool]” to parameter “expression” of type “Dict[ExpressionField | str, Any]” in the “set” function Unable to assign type 'bool' to type 'ExpressionField | str » “bool” is not compatible with “ExpressionField” “bool” is not compatible with “str”PylancereportGeneralTypeIssues (variable) published: bool

im trying increase an integer using the inc method and have this error pylance : Unable to assign argument of type “dict[int, int]” to parameter “expression” of type “Dict[ExpressionField | str, Any]” in the “inc” function Cannot assign type 'int' to type 'ExpressionField | str » “int” is not compatible with “ExpressionField” “int” is not compatible with “str” Pylance

error on using delete method Missing argument for parameter "self"PylancereportGeneralTypeIssues (method) delete: _Wrapped[..., Unknown, (self: Unknown, *args: Unknown, skip_actions: List[ActionDirections | str] | None = None, **kwargs: Unknown), Coroutine[Any, Any, Unknown ]]

To Reproduce

class Character(Document):
    published: bool
    age: int
    class Settings:
        name = "Characters"
    test = await Character.find_one()
    if test:
        await test.set({Character.published: True})
        await test.inc({Character.age:1})
        await test.delete()
CAPITAINMARVEL commented 11 months ago

the function itself do the correct things, its just the pylance errors (i tried my best to explain it im still new on doing github issues)

roman-right commented 11 months ago

Hi! Thank you for the catch. I'll check and fix it this/next week.

CAPITAINMARVEL commented 11 months ago
class DocPlayer(Document):
    money: int

await DocPlayer.find_all().sort(-DocPlayer.money).to_list()

Cannot assign argument of type "int" to parameter "args" of type "str | Tuple[str, SortDirection] | List[Tuple[str, SortDirection]] | None” in “sort” function Cannot assign type 'int' to type 'str | Tuple[str, SortDirection] | List[Tuple[str, SortDirection]] | None » “int” is not compatible with “str” “int” is not compatible with “Tuple[str, SortDirection]” “int” is not compatible with “List[Tuple[str, SortDirection]]” Type cannot be assigned to type 'None'

another one that is a bit annoying on trying to sort by highest to lowest

roman-right commented 9 months ago

Hi, Sorry for the delay. I'll try to pick up typing bugs soon. But I have to fix runtime bugs firstly.