Commit 02dd58f
authored
🐛 fix(docstring): survive a re-entrant docstring handler (#758)
Building the docs died with `ExtensionError: Handler <function
process_docstring ...> threw an exception (exception: 'Config' object
has no attribute '_annotation_globals')`, reported in #750 against
3.5-3.6. `process_docstring` hangs three values off the config for the
formatting code to read and deletes them in a `finally`. That works
until documenting one object starts documenting another before the first
one finishes: the inner call deletes the attributes, and the outer call
then raises on its own teardown, which is the error the reporter saw. On
their version an autodoc directive sitting in a docstring was enough,
because the throwaway parse that places `:rtype:` ran it. The reproducer
below builds clean since #624 neutralized those directives.
A `typehints_formatter` that documents a nested object still re-enters
the handler on `main`, and still aborts the build the same way. Rather
than block re-entry, the teardown now puts back whatever it found: an
inner call restores the outer call's values, and the outermost call
clears them. Nesting turns into an ordinary save and restore, whatever
the caller did to reach it. 🔁
```python
# conf.py
def setup(app):
import demo
from sphinx_autodoc_typehints import process_docstring
def formatter(annotation, config):
if annotation is int:
process_docstring(app, "function", "demo.helper", demo.helper, None, ["Help."])
return None
app.config.typehints_formatter = formatter
```1 parent 3f6d334 commit 02dd58f
2 files changed
Lines changed: 57 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
206 | 225 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
210 | 231 | | |
211 | 232 | | |
212 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
0 commit comments