Skip to content

Rewrite SessionBase properties to use @property #1129

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

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

adamchainz
Copy link
Contributor

I have made things!

Follow-up to observation in: #1128 (comment)

Rewrite these properties to use @property.

Tested by adding the below at the bottom of django-stubs/contrib/sessions/backends/base.pyi:

reveal_type(SessionBase().session_key)
reveal_type(SessionBase()._session_key)
SessionBase()._session_key = 1

Running Mypy without the fix:

$ mypy django-stubs/contrib/sessions/backends/base.pyi
django-stubs/contrib/sessions/backends/base.pyi:45: note: Revealed type is "Any"
django-stubs/contrib/sessions/backends/base.pyi:46: note: Revealed type is "Any"
Success: no issues found in 1 source file

...and after:

$ mypy django-stubs/contrib/sessions/backends/base.pyi
django-stubs/contrib/sessions/backends/base.pyi:49: note: Revealed type is "builtins.str"
django-stubs/contrib/sessions/backends/base.pyi:50: note: Revealed type is "builtins.str"
django-stubs/contrib/sessions/backends/base.pyi:51: error: Incompatible types in assignment (expression has type "int", variable has type "str")
Found 1 error in 1 file (checked 1 source file)

The correct types are revealed, and the assignment is detected as incorrect.

Related issues

n/a

@sobolevn sobolevn merged commit 0120fc5 into typeddjango:master Aug 26, 2022
@adamchainz adamchainz deleted the session_base_properties branch August 26, 2022 14:25
ljodal added a commit to ljodal/django-stubs that referenced this pull request Sep 29, 2022
This can be None, which type stubs no longer reflect after typeddjango#1129
ljodal added a commit to ljodal/django-stubs that referenced this pull request Sep 29, 2022
This can be None, which type stubs no longer reflect after typeddjango#1129
ljodal added a commit to ljodal/django-stubs that referenced this pull request Sep 29, 2022
This can be None, which type stubs no longer allow after typeddjango#1129
@ljodal ljodal mentioned this pull request Sep 29, 2022
ljodal added a commit to ljodal/django-stubs that referenced this pull request Sep 30, 2022
This can be None, which type stubs no longer allow after typeddjango#1129
adamchainz pushed a commit to ljodal/django-stubs that referenced this pull request Nov 3, 2022
This can be None, which type stubs no longer allow after typeddjango#1129
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.

2 participants