← 输入框|github.com|刷新
Skip to content

#doctest: directives removed from doctest chapter examples #59070

Closed

Description

@terryjreedy
BPO 14865
Nosy @birkenfeld, @terryjreedy, @ssbr, @ezio-melotti, @merwok, @sandrotosi
Superseder
  • bpo-12947: doctest directive examples in library/doctest.html lack the flags
  • 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 = <Date 2012-05-20.21:42:13.895>
    created_at = <Date 2012-05-20.17:58:14.002>
    labels = ['type-bug', 'docs']
    title = '#doctest: directives removed from doctest chapter examples'
    updated_at = <Date 2012-05-20.21:43:40.293>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2012-05-20.21:43:40.293>
    actor = 'terry.reedy'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2012-05-20.21:42:13.895>
    closer = 'terry.reedy'
    components = ['Documentation']
    creation = <Date 2012-05-20.17:58:14.002>
    creator = 'terry.reedy'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 14865
    keywords = []
    message_count = 6.0
    messages = ['161220', '161221', '161224', '161226', '161227', '161234']
    nosy_count = 7.0
    nosy_names = ['georg.brandl', 'terry.reedy', 'Devin Jeanpierre', 'ezio.melotti', 'eric.araujo', 'sandro.tosi', 'docs@python']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '12947'
    type = 'behavior'
    url = 'https://bugs.python.org/issue14865'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. terryjreedy commented on May 20, 2012

      @terryjreedy
      MemberAuthor

      In the doctest section, 25.2.3.5. Option Flags and Directives has examples of using #doctest: directives in the .rst source
      '''
      An example's doctest directives modify doctest's behavior for that single example. Use + to enable the named behavior, or - to disable it.

      For example, this test passes::

         >>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE
         [0,   1,  2,  3,  4,  5,  6,  7,  8,  9,
         10,  11, 12, 13, 14, 15, 16, 17, 18, 19]
      '''
      However, when converted to html or Window's help, the directive is removed. See for example

      http://docs.python.org/py3k/library/doctest.html#option-flags-and-directives

      This was reported on python-list for 2.7 and 3.? (.2 probably) by Steven D'Aprano and verified by me for 3.3.0 Win help. Vincent Vande Vyvre provided quote from 3.? .rst source and I verified it and several more following in 3.3.0.

      I presume the problem is that we now use the same directives to help doctest source examples for other modules and sphinx with our customizations does not know to leave these particular directives in the text after using them.

      I searched issues for '#doctest' and did not see anything about removal.

    2. added
      docs
      type-bug
      on May 20, 2012
    3. terryjreedy commented on May 20, 2012

      @terryjreedy
      MemberAuthor

      This is a somewhat recent reversion.

      3.1.5 (a month ago)
      http://docs.python.org/release/3.1.5/library/doctest.html#module-doctest
      >>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE
      [0,   1,  2,  3,  4,  5,  6,  7,  8,  9,
      10,  11, 12, 13, 14, 15, 16, 17, 18, 19]
      
      3.2.0
      http://docs.python.org/release/3.2/library/doctest.html#module-doctest
      >>> print(list(range(20))) 
      [0,   1,  2,  3,  4,  5,  6,  7,  8,  9,
      10,  11, 12, 13, 14, 15, 16, 17, 18, 19]

      In Py 2, the same change happened between 2.7.2, released June 2011 after 3.2.0, and 2.7.3. So some change was made for 3.2.0 but not ported to 2.7 until several months later, and never ported to 3.1 (or 2.6). I hope this helps.

    4. sandrotosi commented on May 20, 2012

      @sandrotosi
      Contributor

      Hi Terry,
      the same problem recently came up on docs@ and digging into it, it turned out that sphinx is currently ignoring doctest directives[1], but that it was fixed in sphinx 1.1[2].

      [1] https://bitbucket.org/birkenfeld/sphinx/issue/169/strip-doctest-csomments-in-rendered-output
      [2] https://bitbucket.org/birkenfeld/sphinx/changeset/d91bf8e465ef

      It's likely the bug is visible on the active branches because recently they were updated to use the same sphinx version.

      We can probably plan to update the sphinx we use for the doc - what do you think about it?

    5. terryjreedy commented on May 20, 2012

      @terryjreedy
      MemberAuthor

      To my mind, stripping is not ignoring ;-), but I understand what you mean, sphinx ignores as it pays attention and strips.

      [2] is the commit for [1], and both are from 3 years ago, long before 3.2.0. Does the true-by-default trim_doctest_flags config value work on a file by file basis, so that it can just be added to doctest.rst?

      I have no opinion of sphinx versions, which I am ignorant about. I just know that the mistaken stripping destroys the value of the examples, making the result very confusing.

    6. ssbr commented on May 20, 2012

      ssbrmannequin
      Mannequin

      This is a duplicate of http://bugs.python.org/issue12947

    7. terryjreedy commented on May 20, 2012

      @terryjreedy
      MemberAuthor

      Thanks for discovering that. I did not search well enough.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docstype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions