beanie
beanie copied to clipboard
[BUG] type pylance
Describe the bug so I did try the example from github and i have a pylance error
To Reproduce (beanie example)
other issue https://github.com/BeanieODM/beanie/issues/807 and https://github.com/BeanieODM/beanie/issues/864
I have also another error : Call expression not allowed in typePylance expression (on the Indexed(float))
class Product(Document):
name: str # You can use normal types just like in pydantic
description: Optional[str] = None
price: Indexed(float) # You can also specify that a field should correspond to an index
category: Category # You can include pydantic models as well
Thank you for the catch
I also have another isue with sorting
It is not possible to assign the argument of type “int” to the 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” Pylance
await DocPlayer.find(DocPlayer.lb.rep >0).sort(-DocPlayer.lb.rep).project(ProjectTopRep).to_list()
class ProjectTopRep(BaseModel):
player_id: int
rep: int
class Settings:
projection = {"player_id": True, "rep": "$lb.rep"}
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”Pylanc
how to do it :
class Player(Document):
player_id: int
hidestats: bool
await Product.find_one().set({Player.hidestats : True})
It does update the field but Pylance do not like it
class Quiz(Document):
right: int
await Quiz.find_one(Quiz.id == self.quiz.id).inc({Quiz.right : 1})
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”PylancereportGeneralTypeIssues (variable) right: int
class Player(Document):
money: int
data = await Player.find(
Player.money >0,
sort=[(Player.money, -1)]
).to_list()
Unable to assign argument of type “list[tuple[int, Literal[-1]]]” to parameter “sort” of type “str | List[Tuple[str, SortDirection]] | None” in “find” function “int” is not compatible with “str” “Literal[-1]” is not compatible with “SortDirection” Pylance
class Player(Document):
money: int
data = await Player.find(
Player.money >0).sort(-Player.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” Pylance