Visitar URL original
IDLE: Fix shell comment anomalies · Issue #88491 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20261011055812/https://github.com/python/cpython/issues/88491
Skip to content

IDLE: Fix shell comment anomalies #88491

Description

@terryjreedy
BPO 44325
Nosy @terryjreedy, @taleinat

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 2021-06-06.20:44:50.458>
labels = ['type-bug', '3.9', '3.10', '3.11']
title = 'IDLE: Fix shell comment anomalies'
updated_at = <Date 2021-06-07.10:44:58.706>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2021-06-07.10:44:58.706>
actor = 'taleinat'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2021-06-06.20:44:50.458>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 44325
keywords = []
message_count = 5.0
messages = ['395214', '395227', '395258', '395259', '395260']
nosy_count = 2.0
nosy_names = ['terry.reedy', 'taleinat']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'test needed'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44325'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Activity

  1. terryjreedy commented on Jun 6, 2021

    @terryjreedy
    MemberAuthor

    Spinoff from bpo-38673, about standard REPL, msg356271 (me) and msg356348 (Guido). In the following interactions, no blank lines were entered.

    3.9 behavior
    >>> #a
    >>> # a
    >>>  #a
    >>>  # a
     
    >>> 
    Mystery 1: why the blank continuation line?

    I previously wrote
    "ast.dump(ast.parse(' # a\n', '', 'single')) gives the same result, 'Module(body=[], type_ignores=[])', as without [space after #]".
    Today, 3.8.10, 3.9.5, 3.10, and 3.11 say "unexpected EOF while parsing".

    3.10 behavior
    >>> #a
    ...  
    >>> # a
    >>>  #a
    >>>  # a
    ...  
    >>>
    Mystery 2: why the new continuation line after '#a'?
    
    3.11 behavior
    >>> #a
    >>> # a
    >>> #a
    >>>  #a
    >>>  # a
    ...  
    >>>
    Mystery 3: why does the 3.10 regression for '#a' disappear?

    Perhaps IDLE should handle initial blank lines itself, but I will investigate what codeop._maybe_compile is getting and doing in the different cases first.

  2. terryjreedy commented on Jun 6, 2021

    @terryjreedy
    MemberAuthor

    I added debug prints to _maybe_compile and confirmed

    1. trailing whitespace (' ' and '\t' at least) is removed before this function is called. I presume in IDLE rather than code.II, but cannot find where. It is not with .rstrip. (Note: doing so after '\' is a bug in that it lets buggy input such as 'a\ \n + 2' run instead of raising.)
    1. code is otherwise delivered intact and blanks lines become 'pass'. Thus any difference noted above is not due to compile().
    The report was based on Windows with 3.9.5, 3.10.0b2, and fresh main.  I repeated the Shell experiments on a Mac Airbook, and a slower machine, with 3.10.b1.  There was never a spurious ... -- once the proper >>> was printed.  However, I sometimes saw ... appear very briefly, only to be overwritten with >>>.  (I saw this once, *very briefly*, on Windows with main, on the first comment I tried.)  I also saw ... appear and disappear when there was a SyntaxError or print output.  I suspect that Sidebar always adds ..., only to be deleted or overwritten when it is a mistake.

    I then tried 3.9.5 on the Mac and saw a spurious blank line with ' # a' once, on the first try, but not again in several attempts. There seems to be a 'warmup' effect.

    My conclusion so far: sidebar might be a culprit, but because of the 3.9 behavior, I think it more likely a victim of pyshell prematurely marking the new line as a possible continuation line. As long as there was not continuation prompt, this might seem innocuous. But it might also be a factor in other spurious blank lines. In particular,

    >>> if 1: # Hit return on indented line.
    ...     print(2)
    ... 
    ...     < undeleted 4 space indent
        2
    >>> if 1: # Delete indent first.  Get proper behavior.
    ...     print(2)
    ...
        2
    >>>

    I am stopping here. Tal, what do you think with your better knowledge of pyshell internals?

  3. taleinat commented on Jun 7, 2021

    @taleinat
    Contributor
    1. trailing whitespace (' ' and '\t' at least) is removed before this function is called. I presume in IDLE rather than code.II, but cannot find where. It is not with .rstrip.

    You're probably looking for this code in EditorWindow.newline_and_indent_event():

    # Strip whitespace after insert point.
    while text.get("insert") in " \t":
        text.delete("insert")

    See:

    # Strip whitespace after insert point.

  4. taleinat commented on Jun 7, 2021

    @taleinat
    Contributor

    However, I sometimes saw ... appear very briefly, only to be overwritten with >>>.

    This is a known limitation of the current sidebar implementation, which was very difficult to avoid and was considered minor enough to let be for now.

  5. taleinat commented on Jun 7, 2021

    @taleinat
    Contributor

    The sidebar doesn't seem to be causing this issue, it's just making it a bit more visible, since what was previously a blank line now also has a more visible "..." continuation prompt.

  6. 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

    topic-IDLEtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions