Skip to content

Doctest paste regression with multiline strings. #15259

Description

@Erotemic

Starting in IPython 9.10.0 the following code no longer strips doctest prompts correctly (with both standard doctest style as well as the extended xdoctest style - which I would love if we kept support for).

Consider 3 doctest style with multiline strings. The first one is supported by standard doctest, the later are supported by xdoctest as well.

python -c 'if 1:
    import textwrap
    from IPython.core.inputtransformer2 import TransformerManager

    q = chr(39) * 3
    cell = textwrap.dedent(
        f"""
        >>> x = (
        ...     r{q}
        ...     hello
        ...     {q})
        """)
    got = TransformerManager().transform_cell(cell)
    print(got)
'


python -c 'if 1:
    import textwrap
    from IPython.core.inputtransformer2 import TransformerManager

    q = chr(39) * 3
    cell = textwrap.dedent(
        f"""
        >>> x = (
        >>>     r{q}
        >>>     hello
        >>>     {q})
        """)
    got = TransformerManager().transform_cell(cell)
    print(got)
'

python -c 'if 1:
    import textwrap
    from IPython.core.inputtransformer2 import TransformerManager

    q = chr(39) * 3
    cell = textwrap.dedent(
        f"""
        >>> x = (
                r{q}
                hello
                {q})
        """)
    got = TransformerManager().transform_cell(cell)
    print(got)
'

On version 9.9.0 I correctly get:

x = (
    r'''
    hello
    ''')

x = (
    r'''
    hello
    ''')

x = (
        r'''
        hello
        ''')

Starting in 9.10.0 I get incorrect stripping for the first two:

x = (
...     r'''
...     hello
...     ''')

x = (
>>>     r'''
>>>     hello
>>>     ''')

x = (
        r'''
        hello
        ''')

This looks like it is a result of: #15110

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions