Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctest.DocTestFinder reports incorrect line numbers with exclude_empty=False #72436

Closed
cpitclaudel mannequin opened this issue Sep 22, 2016 · 3 comments
Closed

doctest.DocTestFinder reports incorrect line numbers with exclude_empty=False #72436

cpitclaudel mannequin opened this issue Sep 22, 2016 · 3 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@cpitclaudel
Copy link
Mannequin

cpitclaudel mannequin commented Sep 22, 2016

BPO 28249
Nosy @cpitclaudel, @tirkarthi, @sobolevn, @kumaraditya303
PRs
  • bpo-28249: fix lineno location for empty DocTest instances #30498
  • Files
  • example.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2016-09-22.15:32:20.468>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'doctest.DocTestFinder reports incorrect line numbers with exclude_empty=False'
    updated_at = <Date 2022-01-09.11:39:50.113>
    user = 'https://github.com/cpitclaudel'

    bugs.python.org fields:

    activity = <Date 2022-01-09.11:39:50.113>
    actor = 'kumaraditya'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2016-09-22.15:32:20.468>
    creator = 'cpitclaudel'
    dependencies = []
    files = ['44786']
    hgrepos = []
    issue_num = 28249
    keywords = ['patch']
    message_count = 1.0
    messages = ['277230']
    nosy_count = 4.0
    nosy_names = ['cpitclaudel', 'xtreak', 'sobolevn', 'kumaraditya']
    pr_nums = ['30498']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28249'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @cpitclaudel
    Copy link
    Mannequin Author

    cpitclaudel mannequin commented Sep 22, 2016

    Line numbers reported by the doctest module are wrong when a function does not include a docstring. With the attached example file, running

    python -c "import doctest, example; print(doctest.DocTestFinder(exclude_empty=False).find(example))"
    

    produces

    [<DocTest example from example.py:5 (no examples)>,
     <DocTest example.a from example.py:5 (no examples)>,
     <DocTest example.b from example.py:5 (no examples)>,
     <DocTest example.c from example.py:None (no examples)>]
    

    whereas if one uncomments the docstrings of a and c the output is

    [<DocTest example from example.py:1 (no examples)>,
     <DocTest example.a from example.py:1 (no examples)>,
     <DocTest example.b from example.py:5 (no examples)>,
     <DocTest example.c from example.py:9 (no examples)>]
    

    This bug is due to this line in doctest:

        lineno = self._find_lineno(obj, source_lines)

    The documentation of _find_lineno says this:

        def _find_lineno(self, obj, source_lines):
            """
            Return a line number of the given object's docstring.  Note:
            this method assumes that the object has a docstring.
            """

    This assumption is violated by the call listed above, because of the exclude_empty=False parameter to DocTestFinder().

    I guess lineno should just be None for all methods that do not have a docstring?

    @cpitclaudel cpitclaudel mannequin added the stdlib Python modules in the Lib dir label Sep 22, 2016
    @kumaraditya303 kumaraditya303 added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error labels Jan 9, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @ambv
    Copy link
    Contributor

    ambv commented May 19, 2022

    This is now fixed.

    @ambv ambv closed this as completed May 19, 2022
    @ambv
    Copy link
    Contributor

    ambv commented May 19, 2022

    Thanks, Clément!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants