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.
Files changed (34) hide show
  1. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/PKG-INFO +1 -1
  2. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/pyproject.toml +1 -1
  3. markdown_exec-1.8.3/src/markdown_exec/formatters/_exec_python.py +8 -0
  4. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/python.py +2 -2
  5. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_python.py +26 -0
  6. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/LICENSE +0 -0
  7. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/README.md +0 -0
  8. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/__init__.py +0 -0
  9. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/ansi.css +0 -0
  10. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/debug.py +0 -0
  11. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/__init__.py +0 -0
  12. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/base.py +0 -0
  13. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/bash.py +0 -0
  14. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/console.py +0 -0
  15. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/markdown.py +0 -0
  16. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/pycon.py +0 -0
  17. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/pyodide.py +0 -0
  18. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/sh.py +0 -0
  19. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/formatters/tree.py +0 -0
  20. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/logger.py +0 -0
  21. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/mkdocs_plugin.py +0 -0
  22. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/processors.py +0 -0
  23. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/py.typed +0 -0
  24. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/pyodide.css +0 -0
  25. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/pyodide.js +0 -0
  26. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/src/markdown_exec/rendering.py +0 -0
  27. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/__init__.py +0 -0
  28. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/conftest.py +0 -0
  29. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_base_formatter.py +0 -0
  30. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_converter.py +0 -0
  31. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_shell.py +0 -0
  32. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_toc.py +0 -0
  33. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_tree.py +0 -0
  34. {markdown_exec-1.8.2 → markdown_exec-1.8.3}/tests/test_validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-exec
3
- Version: 1.8.2
3
+ Version: 1.8.3
4
4
  Summary: Utilities to execute code blocks in Markdown files.
5
5
  Keywords: markdown,python,exec,shell,bash,mkdocs
6
6
  Author-Email: =?utf-8?q?Timoth=C3=A9e_Mazzucotelli?= <dev@pawamoy.fr>
@@ -40,7 +40,7 @@ classifiers = [
40
40
  dependencies = [
41
41
  "pymdown-extensions>=9",
42
42
  ]
43
- version = "1.8.2"
43
+ version = "1.8.3"
44
44
 
45
45
  [project.license]
46
46
  text = "ISC"
@@ -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
- compiled = compile(code, filename=code_block_id, mode="exec")
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