From a9b523c7047fe12c49373972c6b092ed5fc29e99 2022-02-25 10:27:06 From: Thomas Nicholas Date: 2022-02-25 10:27:06 Subject: [PATCH] match only pseudo-decorators --- diff --git a/IPython/sphinxext/ipython_directive.py b/IPython/sphinxext/ipython_directive.py index ac09640..093fd7a 100644 --- a/IPython/sphinxext/ipython_directive.py +++ b/IPython/sphinxext/ipython_directive.py @@ -220,6 +220,8 @@ except Exception: # for tokenizing blocks COMMENT, INPUT, OUTPUT = range(3) +PSEUDO_DECORATORS = ["suppress", "verbatim", "savefig", "doctest"] + #----------------------------------------------------------------------------- # Functions and class declarations #----------------------------------------------------------------------------- @@ -263,11 +265,14 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout): block.append((COMMENT, line)) continue - if line_stripped.startswith('@'): - # Here is where we assume there is, at most, one decorator. - # Might need to rethink this. - decorator = line_stripped - continue + if any( + line_stripped.startswith('@' + pseudo_decorator) for pseudo_decorator in PSEUDO_DECORATORS + ): + if decorator: + raise RuntimeError("Applying multiple pseudo-decorators on one line is not supported") + else: + decorator = line_stripped + continue # does this look like an input line? matchin = rgxin.match(line)