Constructor. We include an argument for the outfile to pass to the formatter for it to write to.
(
self,
locals: dict[str, Any] | None = None,
)
| 67 | |
| 68 | class Interp(ReplInterpreter): |
| 69 | def __init__( |
| 70 | self, |
| 71 | locals: dict[str, Any] | None = None, |
| 72 | ) -> None: |
| 73 | """Constructor. |
| 74 | |
| 75 | We include an argument for the outfile to pass to the formatter for it |
| 76 | to write to. |
| 77 | """ |
| 78 | super().__init__(locals) |
| 79 | |
| 80 | # typically changed after being instantiated |
| 81 | # but used when interpreter used corresponding REPL |
| 82 | def write(err_line: str | FmtStr) -> None: |
| 83 | """Default stderr handler for tracebacks |
| 84 | |
| 85 | Accepts FmtStrs so interpreters can output them""" |
| 86 | sys.stderr.write(str(err_line)) |
| 87 | |
| 88 | self.write = write # type: ignore |
| 89 | self.outfile = self |
| 90 | |
| 91 | def writetb(self, lines: Iterable[str]) -> None: |
| 92 | tbtext = "".join(lines) |