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

BeanieUserDatabase type check fails with Pyright #12

Open
barraponto opened this issue Nov 12, 2023 · 2 comments
Open

BeanieUserDatabase type check fails with Pyright #12

barraponto opened this issue Nov 12, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@barraponto
Copy link

Describe the bug

Pyright complains when BeanieUserDatabase gets a subclass of both BeanieBaseUser and beanie.Document.

Argument of type "type[User]" cannot be assigned to parameter "user_model" of type "type[UP_BEANIE@BeanieUserDatabase]" in function "__init__"

To Reproduce

from beanie import Document
from fastapi_users.db import BeanieBaseUser
from fastapi_users_db_beanie import BeanieUserDatabase


class User(BeanieBaseUser, Document):
    pass


async def get_user_db():
    return BeanieUserDatabase(User)

Expected behavior

No type errors.

Configuration

  • Python version : 3.11.6
  • FastAPI Users version : 12.1.2
  • FastAPI Users DB Beanie version : 3.0.0

Additional context

Particularly, I see BeanieBaseUserDocument defined as literally a subclass of both BeanieBaseUser and beanie.Document. But defining a TypeVar bond to BeanieBaseUserDocument does not accept another subclass of the same classes :/

@barraponto barraponto added the bug Something isn't working label Nov 12, 2023
@barraponto
Copy link
Author

So, can you narrow the generic TypeVar to a subclass of two classes, as to ensure it has every property in both classes? No. Well, not in Python, at least for now. There's a Stackoverflow Q&A that correctly points the issue to the lack of Type Intersections in Python. There's a mile-long issue about it in the python/typing repo, but TLDR we're going to wait a while for support to land.

@barraponto
Copy link
Author

As a pragmatic solution to this issue, can we make BeanieBaseUserDocument importable from fastapi_users.db? Would subclassing it have any nefarious side effect?

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

No branches or pull requests

1 participant