BeanieODM / beanie

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

[BUG] mypy does not raise error when trying to access a non-existing attribute from a beanie Document. #918

Closed marwan-alloreview closed 5 months ago

marwan-alloreview commented 5 months ago

Describe the bug mypy does not raise error when trying to access a non-existing attribute from a beanie Document. It works fine with a pydantic model.

To Reproduce

from pydantic import BaseModel
from beanie import Document

class TestPydantic(BaseModel):
    foo: str

class TestBeanie(Document):
    foo: str

test_pydantic = TestPydantic(foo="test")
test_beanie = TestBeanie(foo="test")

print(test_pydantic.bar)  # This is detected as an error by mypy
print(test_beanie.bar)  # This is not

Expected behavior missing attributes in Documents should be detected by mypy the same way as with pydantic's BaseModels

Additional context

beanie = "1.25.0"
mypy = "1.6.1"
marwan-alloreview commented 5 months ago

Sorry, this is likely a duplicate of #671. I am closing the issue.