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

Allow immutable extra_context on TemplateViews #1994

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions django-stubs/views/generic/base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import Callable, Sequence
from typing import Any
from typing import Any, Mapping

from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseBase
Expand All @@ -9,7 +9,7 @@ from django.utils.functional import _Getter
logger: logging.Logger

class ContextMixin:
extra_context: dict[str, Any] | None
extra_context: Mapping[str, Any] | None
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: ...

class View:
Expand Down
16 changes: 16 additions & 0 deletions tests/typecheck/views/generic/test_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- case: generic_template_view_mutable_extra_context
main: |
from django.views.generic import TemplateView

class MyTemplateView(TemplateView):
template_name = "template.html"
extra_context = {}

- case: generic_template_view_immutable_extra_context
main: |
from types import MappingProxyType
from django.views.generic import TemplateView

class MyTemplateView(TemplateView):
template_name = "template.html"
extra_context = MappingProxyType({})