Skip to content

doctest doesn't catch unescaped character literals #129257

@verhovsky

Description

@verhovsky

Bug report

Bug description:

def fn():
    """
    >>> fn()
    '\\u2009'
    >>> fn()  # this one shouldn't work
    '\u2009'
    """
    return '\u2009'


if __name__ == "__main__":
    import doctest
    doctest.testmod()

The second line is wrong because the character literal is not escaped. If you run help(fn) you'll see this

Image

but if you actually run the sample code you'd see

>>> fn()
'\u2009'
>>> fn()
'\u2009'

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions