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

Add SessionBase methods, change SessionStore.get_model_class() return #1517

Merged
merged 3 commits into from
Jun 2, 2023

Conversation

def clear(self) -> None: ...
def is_empty(self) -> bool: ...
def _get_new_session_key(self) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually don't type protected methods, why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_or_create_session_key may needed to be used when overriding SessionStore. For example:

https://github.com/QueraTeam/django-qsessions/blob/ecfd7327ebe32483746704b59fca72f05be07284/qsessions/backends/db.py#LL43C14-L43C14

I don't have any use cases for the others, typed them just in case. I could remove those.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove them :)
We can always bring them back if there are real use-cases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a change to remove the underscore methods.

Comment on lines 22 to 24
def keys(self) -> Any: ...
def values(self) -> Any: ...
def items(self) -> Any: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added them back for now, so I can merge this for the 4.2.1 release.

If there was a good reason to remove them, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In stubs, SessionBase is defined as subclass of dict:

class SessionBase(dict[str, Any]):

not in Django though:

https://github.com/django/django/blob/27fed08e5ff597c813de25b6e89dc300a1f4231b/django/contrib/sessions/backends/base.py#LL33C9-L33C9

Subclassing from dict should cover for keys, values and items (and with proper return values, not just Any)

I'm guessing the subclassing is probably done so as not type all the dict related dunder methods, which are present in Django to ensure dict-like behavior.

@intgr intgr changed the title Improve typing in contrib.session.backends Add SessionBase methods, change SessionStore.get_model_class() return Jun 2, 2023
@intgr intgr self-assigned this Jun 2, 2023
@intgr intgr merged commit 2d27ba6 into typeddjango:master Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants