|
131 | 131 | import atexit |
132 | 132 | import re |
133 | 133 | from abc import ABC, abstractmethod |
134 | | -from dataclasses import dataclass |
| 134 | +from dataclasses import dataclass, field |
135 | 135 | from sys import intern |
136 | 136 | from typing import ( |
137 | 137 | TYPE_CHECKING, |
|
164 | 164 | if TYPE_CHECKING: |
165 | 165 | from collections.abc import Callable, Hashable, Iterator, Mapping, Sequence |
166 | 166 |
|
| 167 | + from mako.template import Template |
167 | 168 | from numpy.typing import DTypeLike, NDArray |
168 | 169 | from pytest import Metafunc |
169 | 170 |
|
@@ -1301,29 +1302,33 @@ def render(self, context: dict[str, Any]) -> str: |
1301 | 1302 | pass |
1302 | 1303 |
|
1303 | 1304 |
|
| 1305 | +@dataclass(frozen=True) |
1304 | 1306 | class _SimpleTextTemplate(_TextTemplate): |
1305 | | - def __init__(self, txt: str) -> None: |
1306 | | - self.txt: str = txt |
| 1307 | + txt: str |
1307 | 1308 |
|
1308 | 1309 | @override |
1309 | 1310 | def render(self, context: dict[str, Any]) -> str: |
1310 | 1311 | return self.txt |
1311 | 1312 |
|
1312 | 1313 |
|
| 1314 | +@dataclass(frozen=True) |
1313 | 1315 | class _PrintfTextTemplate(_TextTemplate): |
1314 | | - def __init__(self, txt: str) -> None: |
1315 | | - self.txt: str = txt |
| 1316 | + txt: str |
1316 | 1317 |
|
1317 | 1318 | @override |
1318 | 1319 | def render(self, context: dict[str, Any]) -> str: |
1319 | 1320 | return self.txt % context |
1320 | 1321 |
|
1321 | 1322 |
|
| 1323 | +@dataclass(frozen=True) |
1322 | 1324 | class _MakoTextTemplate(_TextTemplate): |
1323 | | - def __init__(self, txt: str) -> None: |
| 1325 | + txt: str |
| 1326 | + template: Template = field(init=False) |
| 1327 | + |
| 1328 | + def __post_init__(self) -> None: |
1324 | 1329 | from mako.template import Template |
1325 | 1330 |
|
1326 | | - self.template: Template = Template(txt, strict_undefined=True) |
| 1331 | + object.__setattr__(self, "template", Template(self.txt, strict_undefined=True)) |
1327 | 1332 |
|
1328 | 1333 | @override |
1329 | 1334 | def render(self, context: dict[str, Any]) -> str: |
|
0 commit comments