From 8d2600136a279870d15a3266895db8ad6e29b29c Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 1 Jun 2020 18:41:57 +0200 Subject: [PATCH] Issue 355 (#376) * Mapping instead of Dict type annotation for context in render() with test * removed Union and Context * typo Co-authored-by: Kacper Szmigiel --- django-stubs/shortcuts.pyi | 6 +++--- test-data/typecheck/test_shortcuts.yml | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/django-stubs/shortcuts.pyi b/django-stubs/shortcuts.pyi index 8ac4501..baae36d 100644 --- a/django-stubs/shortcuts.pyi +++ b/django-stubs/shortcuts.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Dict, List, Optional, Protocol, Sequence, Type, TypeVar, Union +from typing import Any, Callable, List, Mapping, Optional, Protocol, Sequence, Type, TypeVar, Union from django.db.models.base import Model from django.http.response import ( @@ -12,7 +12,7 @@ from django.http import HttpRequest def render_to_response( template_name: Union[str, Sequence[str]], - context: Optional[Dict[str, Any]] = ..., + context: Optional[Mapping[str, Any]] = ..., content_type: Optional[str] = ..., status: Optional[int] = ..., using: Optional[str] = ..., @@ -20,7 +20,7 @@ def render_to_response( def render( request: HttpRequest, template_name: Union[str, Sequence[str]], - context: Optional[Dict[str, Any]] = ..., + context: Optional[Mapping[str, Any]] = ..., content_type: Optional[str] = ..., status: Optional[int] = ..., using: Optional[str] = ..., diff --git a/test-data/typecheck/test_shortcuts.yml b/test-data/typecheck/test_shortcuts.yml index e0db4ee..dc11929 100644 --- a/test-data/typecheck/test_shortcuts.yml +++ b/test-data/typecheck/test_shortcuts.yml @@ -36,3 +36,16 @@ from django.db import models class MyUser(models.Model): pass + +- case: check_render_function_arguments_annotations + main: | + from typing import Any + from typing_extensions import TypedDict + from django.shortcuts import render + from django.http.request import HttpRequest + + TestContext = TypedDict("TestContext", {"user": Any}) + test_context: TestContext = {"user": "test"} + reveal_type(test_context) # N: Revealed type is 'TypedDict('main.TestContext', {'user': Any})' + reveal_type(render(HttpRequest(), '', test_context)) # N: Revealed type is 'django.http.response.HttpResponse' +