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

Mypy issues for odmantic 1.0.0 #391

Open
laveolus opened this issue Dec 19, 2023 · 2 comments
Open

Mypy issues for odmantic 1.0.0 #391

laveolus opened this issue Dec 19, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@laveolus
Copy link

Bug

Following the odmantic 1.0.0 examples and trying to upgrade odmantic/pydantic to V2 , I can find several issues in mypy.

Errors explained as comments below.

Current Behavior

from typing import Optional
from motor.core import AgnosticCollection

from odmantic import Model, Field
from odmantic.config import ODMConfigDict


class A(Model):
    test: Optional[str] = Field(default=None)


# Missing named argument "id" for "A" Mypy (call-arg)
A(test="bla")


class B(Model):
    # Extra key "indexes" for TypedDict "ConfigDict" Mypy (typeddict-unknown-key)
    model_config = {"collection": "B"}


# Fixed: using type explicitly
class B_OK(Model):
    model_config = ODMConfigDict(collection="B")


from odmantic import AIOEngine, Model

engine = AIOEngine()
collection = engine.get_collection(B_OK)
# AsyncIOMotorCollection? has no attribute "find" Mypy (attr-defined)
collection.find({})

# This fixes the issue
collection2: AgnosticCollection = engine.get_collection(B_OK)

Environment

  • ODMantic version: 1.0.0
  • pydantic version: 2.5.2
    pydantic-core version: 2.14.5
    pydantic-core build: profile=release pgo=true
    install path: /home/sander/Projects/application.status.backend/.venv/lib/python3.9/site-packages/pydantic
    python version: 3.9.18 (main, Aug 25 2023, 13:20:14) [GCC 11.4.0]
    platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
    related packages: mypy-1.7.1 typing_extensions-4.9.0 fastapi-0.105.0
@laveolus laveolus added the bug Something isn't working label Dec 19, 2023
@Mokto
Copy link
Contributor

Mokto commented Jan 13, 2024

Same issue here with pyright.

https://github.com/art049/odmantic/blob/master/odmantic/model.py#L946 this line forces "Missing named argument "id" for "A" on type checkers

@Mokto Mokto mentioned this issue Jan 13, 2024
@bobuk
Copy link

bobuk commented Mar 19, 2024

Hey! Just wondering, why this fix wasn't in the latest release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants