markdown-exec 1.8.2__tar.gz → 1.8.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/PKG-INFO +1 -1
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/pyproject.toml +1 -1
- markdown_exec-1.8.3/src/markdown_exec/formatters/_exec_python.py +8 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/python.py +2 -2
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_python.py +26 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/LICENSE +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/README.md +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/__init__.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/ansi.css +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/debug.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/__init__.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/base.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/bash.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/console.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/markdown.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/pycon.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/pyodide.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/sh.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/tree.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/logger.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/mkdocs_plugin.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/processors.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/py.typed +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/pyodide.css +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/pyodide.js +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/rendering.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/__init__.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/conftest.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_base_formatter.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_converter.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_shell.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_toc.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_tree.py +0 -0
- {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_validator.py +0 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
"""Special module without future annotations for executing Python code."""
|
2
|
+
|
3
|
+
from typing import Any, Dict, Optional
|
4
|
+
|
5
|
+
|
6
|
+
def exec_python(code: str, filename: str, exec_globals: Optional[Dict[str, Any]] = None) -> None:
|
7
|
+
compiled = compile(code, filename=filename, mode="exec")
|
8
|
+
exec(compiled, exec_globals) # noqa: S102
|
@@ -11,6 +11,7 @@ from io import StringIO
|
|
11
11
|
from types import ModuleType
|
12
12
|
from typing import Any
|
13
13
|
|
14
|
+
from markdown_exec.formatters._exec_python import exec_python
|
14
15
|
from markdown_exec.formatters.base import ExecutionError, base_format
|
15
16
|
from markdown_exec.rendering import code_block
|
16
17
|
|
@@ -67,8 +68,7 @@ def _run_python(
|
|
67
68
|
exec_globals["print"] = partial(_buffer_print, buffer)
|
68
69
|
|
69
70
|
try:
|
70
|
-
|
71
|
-
exec(compiled, exec_globals) # noqa: S102
|
71
|
+
exec_python(code, code_block_id, exec_globals)
|
72
72
|
except Exception as error: # noqa: BLE001
|
73
73
|
trace = traceback.TracebackException.from_exception(error)
|
74
74
|
for frame in trace.stack:
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
+
import re
|
5
6
|
from textwrap import dedent
|
6
7
|
from typing import TYPE_CHECKING
|
7
8
|
|
@@ -203,3 +204,28 @@ def test_functions_have_a_module_attribute(md: Markdown) -> None:
|
|
203
204
|
),
|
204
205
|
)
|
205
206
|
assert "_code_block_n" in html
|
207
|
+
|
208
|
+
|
209
|
+
def test_future_annotations_do_not_leak_into_user_code(md: Markdown) -> None:
|
210
|
+
"""Assert future annotations do not leak into user code.
|
211
|
+
|
212
|
+
Parameters:
|
213
|
+
md: A Markdown instance (fixture).
|
214
|
+
"""
|
215
|
+
html = md.convert(
|
216
|
+
dedent(
|
217
|
+
"""
|
218
|
+
```python exec="1"
|
219
|
+
class Int:
|
220
|
+
...
|
221
|
+
|
222
|
+
def f(x: Int) -> None:
|
223
|
+
return x + 1.0
|
224
|
+
|
225
|
+
print(f"`{f.__annotations__['x']}`")
|
226
|
+
```
|
227
|
+
""",
|
228
|
+
),
|
229
|
+
)
|
230
|
+
assert "<code>Int</code>" not in html
|
231
|
+
assert re.search(r"class '_code_block_n\d+_\.Int'", html)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|