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

assigment error when overriding create_model_instance class method of SessionStore. #2056

Open
abdelrahman725 opened this issue Apr 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@abdelrahman725
Copy link

What's wrong

mypy doesn't recognize the type of the returned class from get_model_class when overriding SessionStore, and because of that it gives false assignemt error alarm when assigning super().create_model_instance(data) to a variable

Example

from django.contrib.sessions.backends.cached_db import SessionStore as CachedDbSessionStore
from django.contrib.sessions.base_session import AbstractBaseSession

# custom session model
class RealmSession(AbstractBaseSession):
   ....custom code

    @classmethod
    @override
    def get_session_store_class(cls) -> Type["SessionStore"]:
        return SessionStore

class SessionStore(CachedDbSessionStore):

    @classmethod
    @override
    def get_model_class(cls) -> Type[RealmSession]:
        return RealmSession

    @override
    def create_model_instance(self, data: Dict[str, Union[int, str]]) -> RealmSession:
        session_object: RealmSession = super().create_model_instance(data) # Error arises here
        return create_realm_session_instance(session_object, data)

mypy output :

Incompatible types in assignment (expression has type "AbstractBaseSession", variable has type "RealmSession")  [assignment]

How is that should be

RealmSession should be the expected return type from super().create_model_instance(data), so no error should arise

@abdelrahman725 abdelrahman725 added the bug Something isn't working label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant