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 doesn't find nested functions #44538

Open
danb37 mannequin opened this issue Feb 1, 2007 · 4 comments
Open

doctest doesn't find nested functions #44538

danb37 mannequin opened this issue Feb 1, 2007 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@danb37
Copy link
Mannequin

danb37 mannequin commented Feb 1, 2007

BPO 1650090
Nosy @tim-one, @bitdancer, @jayvdb
Files
  • doctest_nested_functions.diff: patch against trunk revision 54419
  • doctest_nested_functions-py3.6.diff: Ziga's patch amended version for Python 3.6
  • doctest_nested_functions-py3.6.diff: Python 3.6-remove unnecessary if clause
  • 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 2007-02-01.19:20:32.000>
    labels = ['type-bug', 'tests']
    title = "doctest doesn't find nested functions"
    updated_at = <Date 2015-11-08.07:58:46.085>
    user = 'https://bugs.python.org/danb37'

    bugs.python.org fields:

    activity = <Date 2015-11-08.07:58:46.085>
    actor = 'jayvdb'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tests']
    creation = <Date 2007-02-01.19:20:32.000>
    creator = 'danb37'
    dependencies = []
    files = ['7750', '40977', '40978']
    hgrepos = []
    issue_num = 1650090
    keywords = ['patch']
    message_count = 4.0
    messages = ['51831', '51832', '51833', '110519']
    nosy_count = 6.0
    nosy_names = ['tim.peters', 'zseil', 'pjdelport', 'danb37', 'r.david.murray', 'jayvdb']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1650090'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @danb37
    Copy link
    Mannequin Author

    danb37 mannequin commented Feb 1, 2007

    If a nested function has doctests, they won't be run:
    {{{
    def f():
      '''
      >>> 'a'
      'a'
      '''
      def g():
        '''
        >>> 'a'
        'b'
        '''
        pass

    pass
    }}}

    DocTestFinder will only find f's doctest and won't recurse to find g's, surprising the programmer when they (hopefully) discover that their inner doctest is incorrect!

    @danb37 danb37 mannequin assigned tim-one Feb 1, 2007
    @pjdelport
    Copy link
    Mannequin

    pjdelport mannequin commented Mar 16, 2007

    DocTestFinder uses object inspection to find docstrings, which doesn't really allow this kind of thing: g isn't created until f is actually run.

    Making this possible would probably require implementing an alternate doctest finder based on source code inspection (via the new _ast module?).

    @zseil
    Copy link
    Mannequin

    zseil mannequin commented Mar 17, 2007

    Here is a patch that implements this new functionality.
    I don't know how desireable this feature is, I just
    wanted to see if it could be done.
    File Added: doctest_nested_functions.diff

    @devdanzin devdanzin mannequin added tests Tests in the Lib/test dir performance Performance or resource usage labels Mar 30, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 16, 2010

    I believe that there could be interest in this, has anyone taken over doctest from tim_one?

    @BreamoreBoy BreamoreBoy mannequin unassigned tim-one Jul 16, 2010
    @BreamoreBoy BreamoreBoy mannequin added type-bug An unexpected behavior, bug, or error and removed performance Performance or resource usage labels Jul 16, 2010
    @BreamoreBoy BreamoreBoy mannequin unassigned tim-one Jul 16, 2010
    @BreamoreBoy BreamoreBoy mannequin added type-bug An unexpected behavior, bug, or error and removed performance Performance or resource usage labels Jul 16, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added stdlib Python modules in the Lib dir and removed tests Tests in the Lib/test dir labels Nov 22, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    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