Method: flask.json.provider.DefaultJSONProvider.response
Calls: 27, Exceptions: 1, Paths: 3Back
Path 1: 24 calls (0.89)
tuple (9) () (4) ('dummy',) (1) (0,) (1) (-1,) (1) (1,) (1) (23,) (1) (3.14,) (1) ('s',) (1) ('longer string',) (1)
{} (20) dict (4)
Response (24)
1def response(self, *args: t.Any, **kwargs: t.Any) -> Response:
2 """Serialize the given arguments as JSON, and return a
3 :class:`~flask.Response` object with it. The response mimetype
4 will be "application/json" and can be changed with
5 :attr:`mimetype`.
6
7 If :attr:`compact` is ``False`` or debug mode is enabled, the
8 output will be formatted to be easier to read.
9
10 Either positional or keyword arguments can be given, not both.
11 If no arguments are given, ``None`` is serialized.
12
13 :param args: A single value to serialize, or multiple values to
14 treat as a list to serialize.
15 :param kwargs: Treat as a dict to serialize.
16 """
17 obj = self._prepare_response_obj(args, kwargs)
18 dump_args: dict[str, t.Any] = {}
19
20 if (self.compact is None and self._app.debug) or self.compact is False:
21 dump_args.setdefault("indent", 2)
22 else:
23 dump_args.setdefault("separators", (",", ":"))
24
25 return self._app.response_class(
26 f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype
27 )
Path 2: 2 calls (0.07)
tuple (1) () (1)
{} (1) dict (1)
Response (2)
1def response(self, *args: t.Any, **kwargs: t.Any) -> Response:
2 """Serialize the given arguments as JSON, and return a
3 :class:`~flask.Response` object with it. The response mimetype
4 will be "application/json" and can be changed with
5 :attr:`mimetype`.
6
7 If :attr:`compact` is ``False`` or debug mode is enabled, the
8 output will be formatted to be easier to read.
9
10 Either positional or keyword arguments can be given, not both.
11 If no arguments are given, ``None`` is serialized.
12
13 :param args: A single value to serialize, or multiple values to
14 treat as a list to serialize.
15 :param kwargs: Treat as a dict to serialize.
16 """
17 obj = self._prepare_response_obj(args, kwargs)
18 dump_args: dict[str, t.Any] = {}
19
20 if (self.compact is None and self._app.debug) or self.compact is False:
21 dump_args.setdefault("indent", 2)
22 else:
23 dump_args.setdefault("separators", (",", ":"))
24
25 return self._app.response_class(
26 f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype
27 )
Path 3: 1 calls (0.04)
('fake args',) (1)
{'kwargs': 'fake'} (1)
TypeError (1)
1def response(self, *args: t.Any, **kwargs: t.Any) -> Response:
2 """Serialize the given arguments as JSON, and return a
3 :class:`~flask.Response` object with it. The response mimetype
4 will be "application/json" and can be changed with
5 :attr:`mimetype`.
6
7 If :attr:`compact` is ``False`` or debug mode is enabled, the
8 output will be formatted to be easier to read.
9
10 Either positional or keyword arguments can be given, not both.
11 If no arguments are given, ``None`` is serialized.
12
13 :param args: A single value to serialize, or multiple values to
14 treat as a list to serialize.
15 :param kwargs: Treat as a dict to serialize.
16 """
17 obj = self._prepare_response_obj(args, kwargs)
18 dump_args: dict[str, t.Any] = {}
19
20 if (self.compact is None and self._app.debug) or self.compact is False:
21 dump_args.setdefault("indent", 2)
22 else:
23 dump_args.setdefault("separators", (",", ":"))
24
25 return self._app.response_class(
26 f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype
27 )