Skip to content

class docstring is removed in interactive mode  #124022

Closed
@iritkatriel

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

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