Skip to content

Update doctect SyntaxErrors for location range #89412

Description

@akulakov
BPO 45249
Nosy @terryjreedy, @blueyed, @pablogsal, @miss-islington, @Fidget-Spinner, @akulakov
PRs
  • bpo-45249: Add regression test for display of SyntaxError range indicator in doctests #28567
  • bpo-45249: Ensure the traceback module prints correctly syntax errors with ranges #28575
  • [3.10] bpo-45249: Ensure the traceback module prints correctly syntax errors with ranges (GH-28575) #28587
  • bpo-45249: Fix caret location when end_offset is set to 0 #28854
  • bpo-45249: Fix caret location when end_offset is set to 0 #28855
  • [3.10] bpo-45249: Fix caret location when end_offset is set to 0 (GH-28855) #28994
  • 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 2021-10-16.17:37:28.444>
    created_at = <Date 2021-09-20.16:30:58.559>
    labels = ['type-bug', 'library', '3.10', '3.11']
    title = 'Update doctect SyntaxErrors for location range'
    updated_at = <Date 2021-10-16.17:51:11.950>
    user = 'https://github.com/akulakov'

    bugs.python.org fields:

    activity = <Date 2021-10-16.17:51:11.950>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-16.17:37:28.444>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2021-09-20.16:30:58.559>
    creator = 'andrei.avk'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45249
    keywords = ['patch']
    message_count = 18.0
    messages = ['402257', '402258', '402260', '402263', '402268', '402269', '402271', '402284', '402589', '402652', '402662', '402670', '402739', '402742', '403157', '403588', '404103', '404106']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'blueyed', 'pablogsal', 'miss-islington', 'kj', 'andrei.avk']
    pr_nums = ['28567', '28575', '28587', '28854', '28855', '28994']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45249'
    versions = ['Python 3.10', 'Python 3.11']

    Linked PRs

    Activity

    1. akulakov commented on Sep 20, 2021

      @akulakov
      ContributorAuthor

      It seems like fine grained error locations do not work in failed doctest traceback output:

      version 3.11.0a0

      file contents:
      ------------------

      def a(x):
          """
          >>> 1 1
          1
          """
      import doctest
      doctest.testmod()

      OUTPUT
      -------

      Failed example:
          1 1
      Exception raised:
          Traceback (most recent call last):
            File "/Users/ak/opensource/cpython/Lib/doctest.py", line 1348, in __run
              exec(compile(example.source, filename, "single",
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "<doctest __main__.a[0]>", line 1
              1 1
              ^
          SyntaxError: invalid syntax. Perhaps you forgot a comma?

      The location in doctests that causes this:

      exec(compile(example.source, filename, "single",

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      testsTests in the Lib/test dir
      3.11only security fixes
      type-bugAn unexpected behavior, bug, or error
      on Sep 20, 2021
    3. akulakov commented on Sep 20, 2021

      @akulakov
      ContributorAuthor

      I've ran into this when looking at doctest docs, the issue is that they use the old example where a single column is highlighted, I want to update it to explain why doctest output differs from the one you get from REPL, but I probably need to understand why it happens to provide a good explanation.

      Alternatively this may be fixed to be consistent if it's easy enough to do.

    4. pablogsal commented on Sep 20, 2021

      @pablogsal
      Member

      Hummmm, could you explain a bit more in detail what is the expected output? I can see highlighting in the exec call that you pasted:

          exec(compile(example.source, filename, "single",
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      

      The fact that you see those "^^^^^^" indicate that is working no? What is missing?

    5. akulakov commented on Sep 20, 2021

      @akulakov
      ContributorAuthor

      Sorry, I should have noted I’m referring to the line 1 1
      Which is underlined by a single caret, but on the command line it has 3
      carets as expected.

    6. pablogsal commented on Sep 20, 2021

      @pablogsal
      Member

      Ah, but that is a different issue. This is not PEP-657, this is a SyntaxError, so is related how those are printed, which I think is separared.

    7. pablogsal commented on Sep 20, 2021

      @pablogsal
      Member

      Can you try a doctest that fails on something that is not a SyntaxError.

      Something like:

      >>> def foo(x):
      ...    return x + 42

      >> foo(None)

    8. akulakov commented on Sep 20, 2021

      @akulakov
      ContributorAuthor

      Pablo: that works fine, thanks!

      I will look into updating the doctest docs, and will close this issue later
      today ( or you can close it if you like).

    9. 26 remaining items

    10. miss-islington commented on Oct 16, 2021

      @miss-islington
      Contributor

      New changeset fe0d9e2 by Pablo Galindo Salgado in branch 'main':
      bpo-45249: Fix caret location when end_offset is set to 0 (GH-28855)
      fe0d9e2

    11. miss-islington commented on Oct 16, 2021

      @miss-islington
      Contributor

      New changeset 5df35fa by Miss Islington (bot) in branch '3.10':
      bpo-45249: Fix caret location when end_offset is set to 0 (GH-28855)
      5df35fa

    12. transferred this issue fromon Apr 10, 2022
    13. added 2 commits that reference this issue on May 28, 2023
    14. added a commit that references this issue on Jun 5, 2023
    15. added 3 commits that reference this issue on Jun 5, 2023
    16. added 3 commits that reference this issue on Jun 5, 2023
    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

      3.10 (EOL)end of life3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions