Holds compile time information for us.
| 163 | |
| 164 | |
| 165 | class Frame: |
| 166 | """Holds compile time information for us.""" |
| 167 | |
| 168 | def __init__( |
| 169 | self, |
| 170 | eval_ctx: EvalContext, |
| 171 | parent: t.Optional["Frame"] = None, |
| 172 | level: t.Optional[int] = None, |
| 173 | ) -> None: |
| 174 | self.eval_ctx = eval_ctx |
| 175 | |
| 176 | # the parent of this frame |
| 177 | self.parent = parent |
| 178 | |
| 179 | if parent is None: |
| 180 | self.symbols = Symbols(level=level) |
| 181 | |
| 182 | # in some dynamic inheritance situations the compiler needs to add |
| 183 | # write tests around output statements. |
| 184 | self.require_output_check = False |
| 185 | |
| 186 | # inside some tags we are using a buffer rather than yield statements. |
| 187 | # this for example affects {% filter %} or {% macro %}. If a frame |
| 188 | # is buffered this variable points to the name of the list used as |
| 189 | # buffer. |
| 190 | self.buffer: t.Optional[str] = None |
| 191 | |
| 192 | # the name of the block we're in, otherwise None. |
| 193 | self.block: t.Optional[str] = None |
| 194 | |
| 195 | else: |
| 196 | self.symbols = Symbols(parent.symbols, level=level) |
| 197 | self.require_output_check = parent.require_output_check |
| 198 | self.buffer = parent.buffer |
| 199 | self.block = parent.block |
| 200 | |
| 201 | # a toplevel frame is the root + soft frames such as if conditions. |
| 202 | self.toplevel = False |
| 203 | |
| 204 | # the root frame is basically just the outermost frame, so no if |
| 205 | # conditions. This information is used to optimize inheritance |
| 206 | # situations. |
| 207 | self.rootlevel = False |
| 208 | |
| 209 | # variables set inside of loops and blocks should not affect outer frames, |
| 210 | # but they still needs to be kept track of as part of the active context. |
| 211 | self.loop_frame = False |
| 212 | self.block_frame = False |
| 213 | |
| 214 | # track whether the frame is being used in an if-statement or conditional |
| 215 | # expression as it determines which errors should be raised during runtime |
| 216 | # or compile time. |
| 217 | self.soft_frame = False |
| 218 | |
| 219 | def copy(self) -> "Frame": |
| 220 | """Create a copy of the current one.""" |
| 221 | rv = object.__new__(self.__class__) |
| 222 | rv.__dict__.update(self.__dict__) |
no outgoing calls
no test coverage detected