-
-
Notifications
You must be signed in to change notification settings - Fork 458
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
Conversation
def clear(self) -> None: ... | ||
def is_empty(self) -> bool: ... | ||
def _get_new_session_key(self) -> str: ... |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
I don't have any use cases for the others, typed them just in case. I could remove those.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
def keys(self) -> Any: ... | ||
def values(self) -> Any: ... | ||
def items(self) -> Any: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these 3 methods? Looks like they're present still: https://github.com/django/django/blob/main/django/contrib/sessions/backends/base.py#L121C1-L129
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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.
contrib.session.backends
https://github.com/django/django/blob/main/django/contrib/sessions/backends/base.py
https://github.com/django/django/blob/main/django/contrib/sessions/backends/db.py