r"""Check that cell does not already contain TransformerManager transformations, or non-Python cell magics, which might cause tokenizer_rt to break because of indentations. If a cell contains ``!ls``, then it'll be transformed to ``get_ipython().system('ls')``. However, if the cell
(src: str, mode: Mode)
| 62 | |
| 63 | |
| 64 | def validate_cell(src: str, mode: Mode) -> None: |
| 65 | r"""Check that cell does not already contain TransformerManager transformations, |
| 66 | or non-Python cell magics, which might cause tokenizer_rt to break because of |
| 67 | indentations. |
| 68 | |
| 69 | If a cell contains ``!ls``, then it'll be transformed to |
| 70 | ``get_ipython().system('ls')``. However, if the cell originally contained |
| 71 | ``get_ipython().system('ls')``, then it would get transformed in the same way: |
| 72 | |
| 73 | >>> TransformerManager().transform_cell("get_ipython().system('ls')") |
| 74 | "get_ipython().system('ls')\n" |
| 75 | >>> TransformerManager().transform_cell("!ls") |
| 76 | "get_ipython().system('ls')\n" |
| 77 | |
| 78 | Due to the impossibility of safely roundtripping in such situations, cells |
| 79 | containing transformed magics will be ignored. |
| 80 | """ |
| 81 | if any(transformed_magic in src for transformed_magic in TRANSFORMED_MAGICS): |
| 82 | raise NothingChanged |
| 83 | |
| 84 | line = _get_code_start(src) |
| 85 | if line.startswith("%%") and ( |
| 86 | line.split(maxsplit=1)[0][2:] |
| 87 | not in PYTHON_CELL_MAGICS | mode.python_cell_magics |
| 88 | ): |
| 89 | raise NothingChanged |
| 90 | |
| 91 | |
| 92 | def remove_trailing_semicolon(src: str) -> tuple[str, bool]: |
no test coverage detected