Skip to content

[peewee] Incorrect type for field operations #14330

Open
@insideable

Description

@insideable

Following code fails on mypy and pyright checks:

from peewee import CharField, Model, PrimaryKeyField


class Foo(Model):
    id = PrimaryKeyField()
    name = CharField()


def find_foo_by_name(name: str) -> Foo:
    return Foo.get(Foo.name.in_(name))  # <- mypy error here


find_foo_by_name('foo bar')

mypy:

$ poetry run mypy main.py
main.py:10: error: Too few arguments  [call-arg]
main.py:10: note: "in_" is considered instance variable, to make it class variable use ClassVar[...]
main.py:10: error: Argument 1 has incompatible type "str"; expected "CharField"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

pyright:

$ poetry run pyright main.py
/tmp/a/main.py
  /tmp/a/main.py:10:20 - error: Expected 1 more positional argument (reportCallIssue)
1 error, 0 warnings, 0 informations

There is a PR which fixes the issue: #14275

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions