1
+ from __future__ import annotations
2
+
1
3
import inspect
2
4
import linecache
3
5
import os .path
4
6
import sys
5
7
import warnings
6
8
from pprint import PrettyPrinter , pformat
7
- from typing import Any , Dict , List , Optional , Sequence , Tuple , Union
9
+ from typing import Any , Sequence
8
10
9
11
from asgiref .local import Local
10
12
from django .http import QueryDict
17
19
_local_data = Local ()
18
20
19
21
20
- def _is_excluded_frame (frame : Any , excluded_modules : Optional [ Sequence [str ]] ) -> bool :
22
+ def _is_excluded_frame (frame : Any , excluded_modules : Sequence [str ] | None ) -> bool :
21
23
if not excluded_modules :
22
24
return False
23
25
frame_module = frame .f_globals .get ("__name__" )
@@ -39,7 +41,7 @@ def _stack_trace_deprecation_warning() -> None:
39
41
)
40
42
41
43
42
- def tidy_stacktrace (stack : List [stubs .InspectStack ]) -> stubs .TidyStackTrace :
44
+ def tidy_stacktrace (stack : list [stubs .InspectStack ]) -> stubs .TidyStackTrace :
43
45
"""
44
46
Clean up stacktrace and remove all entries that are excluded by the
45
47
HIDE_IN_STACKTRACES setting.
@@ -99,7 +101,7 @@ def render_stacktrace(trace: stubs.TidyStackTrace) -> SafeString:
99
101
return mark_safe (html )
100
102
101
103
102
- def get_template_info () -> Optional [ Dict [ str , Any ]] :
104
+ def get_template_info () -> dict [ str , Any ] | None :
103
105
template_info = None
104
106
cur_frame = sys ._getframe ().f_back
105
107
try :
@@ -129,7 +131,7 @@ def get_template_info() -> Optional[Dict[str, Any]]:
129
131
130
132
def get_template_context (
131
133
node : Node , context : stubs .RequestContext , context_lines : int = 3
132
- ) -> Dict [str , Any ]:
134
+ ) -> dict [str , Any ]:
133
135
line , source_lines , name = get_template_source_from_exception_info (node , context )
134
136
debug_context = []
135
137
start = max (1 , line - context_lines )
@@ -146,7 +148,7 @@ def get_template_context(
146
148
147
149
def get_template_source_from_exception_info (
148
150
node : Node , context : stubs .RequestContext
149
- ) -> Tuple [int , List [ Tuple [int , str ]], str ]:
151
+ ) -> tuple [int , list [ tuple [int , str ]], str ]:
150
152
if context .template .origin == node .origin :
151
153
exception_info = context .template .get_exception_info (
152
154
Exception ("DDT" ), node .token
@@ -213,8 +215,8 @@ def getframeinfo(frame: Any, context: int = 1) -> inspect.Traceback:
213
215
214
216
215
217
def get_sorted_request_variable (
216
- variable : Union [ Dict [ str , Any ], QueryDict ] ,
217
- ) -> Dict [str , Union [ List [ Tuple [ str , Any ]], Any ] ]:
218
+ variable : dict [ str , Any ] | QueryDict ,
219
+ ) -> dict [str , list [ tuple [ str , Any ]] | Any ]:
218
220
"""
219
221
Get a data structure for showing a sorted list of variables from the
220
222
request data.
@@ -228,7 +230,7 @@ def get_sorted_request_variable(
228
230
return {"raw" : variable }
229
231
230
232
231
- def get_stack (context = 1 ) -> List [stubs .InspectStack ]:
233
+ def get_stack (context = 1 ) -> list [stubs .InspectStack ]:
232
234
"""
233
235
Get a list of records for a frame and all higher (calling) frames.
234
236
@@ -286,7 +288,7 @@ def get_source_file(self, frame):
286
288
def get_stack_trace (
287
289
self ,
288
290
* ,
289
- excluded_modules : Optional [ Sequence [str ]] = None ,
291
+ excluded_modules : Sequence [str ] | None = None ,
290
292
include_locals : bool = False ,
291
293
skip : int = 0 ,
292
294
):
0 commit comments