Build the finalize function to be used on constants and at runtime. Cached so it's only created once for all output nodes. Returns a ``namedtuple`` with the following attributes: ``const`` A function to finalize constant data at compile time. ``src``
(self)
| 1374 | _finalize: t.Optional[_FinalizeInfo] = None |
| 1375 | |
| 1376 | def _make_finalize(self) -> _FinalizeInfo: |
| 1377 | """Build the finalize function to be used on constants and at |
| 1378 | runtime. Cached so it's only created once for all output nodes. |
| 1379 | |
| 1380 | Returns a ``namedtuple`` with the following attributes: |
| 1381 | |
| 1382 | ``const`` |
| 1383 | A function to finalize constant data at compile time. |
| 1384 | |
| 1385 | ``src`` |
| 1386 | Source code to output around nodes to be evaluated at |
| 1387 | runtime. |
| 1388 | """ |
| 1389 | if self._finalize is not None: |
| 1390 | return self._finalize |
| 1391 | |
| 1392 | finalize: t.Optional[t.Callable[..., t.Any]] |
| 1393 | finalize = default = self._default_finalize |
| 1394 | src = None |
| 1395 | |
| 1396 | if self.environment.finalize: |
| 1397 | src = "environment.finalize(" |
| 1398 | env_finalize = self.environment.finalize |
| 1399 | pass_arg = { |
| 1400 | _PassArg.context: "context", |
| 1401 | _PassArg.eval_context: "context.eval_ctx", |
| 1402 | _PassArg.environment: "environment", |
| 1403 | }.get( |
| 1404 | _PassArg.from_obj(env_finalize) # type: ignore |
| 1405 | ) |
| 1406 | finalize = None |
| 1407 | |
| 1408 | if pass_arg is None: |
| 1409 | |
| 1410 | def finalize(value: t.Any) -> t.Any: |
| 1411 | return default(env_finalize(value)) |
| 1412 | |
| 1413 | else: |
| 1414 | src = f"{src}{pass_arg}, " |
| 1415 | |
| 1416 | if pass_arg == "environment": |
| 1417 | |
| 1418 | def finalize(value: t.Any) -> t.Any: |
| 1419 | return default(env_finalize(self.environment, value)) |
| 1420 | |
| 1421 | self._finalize = self._FinalizeInfo(finalize, src) |
| 1422 | return self._finalize |
| 1423 | |
| 1424 | def _output_const_repr(self, group: t.Iterable[t.Any]) -> str: |
| 1425 | """Given a group of constant values converted from ``Output`` |
no test coverage detected