Skip to content

class docstring is removed in interactive mode  #124022

Closed

Description

@iritkatriel
>>> import dis
>>> src = """class C:
...     "docstring"
...     x = 42"""
>>> dis.dis(compile(src, "<string>", "single"))
  0           RESUME                   0

  1           LOAD_BUILD_CLASS
              PUSH_NULL
              LOAD_CONST               0 (<code object C at 0x10c3b4f40, file "<string>", line 1>)
              MAKE_FUNCTION
              LOAD_CONST               1 ('C')
              CALL                     2
              STORE_NAME               0 (C)
              RETURN_CONST             2 (None)

Disassembly of <code object C at 0x10c3b4f40, file "<string>", line 1>:
  1           RESUME                   0
              LOAD_NAME                0 (__name__)
              STORE_NAME               1 (__module__)
              LOAD_CONST               0 ('C')
              STORE_NAME               2 (__qualname__)
              LOAD_CONST               1 (1)
              STORE_NAME               3 (__firstlineno__)

  2           NOP                                             <--- line 2 is where the docstring is. This NOP shouldn't be here

  3           LOAD_CONST               2 (42)
              STORE_NAME               4 (x)
              LOAD_CONST               3 (())
              STORE_NAME               5 (__static_attributes__)
              RETURN_CONST             4 (None)

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Sep 12, 2024
  2. added a commit that references this issue on Sep 12, 2024
  3. iritkatriel commented on Sep 12, 2024

    @iritkatriel
    MemberAuthor

    Following discussion (see PR) the special handling for interactive mode is new in 3.14, and was inserted by accident. The fix will be to not remove docstrings in interactive mode (as was the case in 3.13).

  4. changed the title [-]class docstring in interactive mode generates a NOP with the docstring's location[/-] [+]class docstring is removed in interactive mode [/+] on Sep 12, 2024
  5. added a commit that references this issue on Sep 13, 2024
  6. added a commit that references this issue on Sep 13, 2024
  7. added a commit that references this issue on Sep 13, 2024
  8. added 2 commits that reference this issue on Sep 13, 2024
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions