Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8e580f

Browse files
authored
Fix attribute after walrus error (felix-hilden#177)
1 parent 6d548f7 commit f8e580f

File tree

7 files changed

+195
-243
lines changed

7 files changed

+195
-243
lines changed

docs/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Fix attribute and call after walrus leading parser error (:issue:`174`)
14+
- Improve error message on uncaught parsing errors (:issue:`177`)
15+
1116
0.17.0 (2025-02-18)
1217
-------------------
1318
Added

src/sphinx_codeautolink/extension/block.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def visit_literal_block(self, node: nodes.literal_block):
196196
"""Visit a generic literal block."""
197197
return self.parse_source(node, node.get("language", self.highlight_lang))
198198

199-
def parse_source( # noqa: C901
199+
def parse_source( # noqa: C901,PLR0912
200200
self, node: nodes.literal_block | nodes.doctest_block, language: str | None
201201
) -> None:
202202
"""Analyse Python code blocks."""
@@ -258,6 +258,12 @@ def parse_source( # noqa: C901
258258
msg = self._parsing_error_msg(e, language, show_source)
259259
logger.warning(msg, type=warn_type, subtype="parse_block", location=node)
260260
return
261+
except Exception as e:
262+
show_source = self._format_source_for_error(
263+
self.global_preface, self.concat_sources, prefaces, transform.source
264+
)
265+
msg = self._parsing_error_msg(e, language, show_source)
266+
raise type(e)(msg) from e
261267

262268
if prefaces or self.concat_sources or self.global_preface:
263269
concat_lens = [s.count("\n") + 1 for s in self.concat_sources]
@@ -302,6 +308,7 @@ def _parsing_error_msg(self, error: Exception, language: str, source: str) -> st
302308
str(error) + f" in document {self.current_document!r}",
303309
f"Parsed source in `{language}` block:",
304310
source,
311+
"",
305312
]
306313
)
307314

0 commit comments

Comments
 (0)