Skip to content

LOAD_DEREF and LOAD_CLOSURE have incorrect opcode metadata flags #151321

Closed

Description

@coroma01

Bug report

Bug description:

LOAD_DEREF is missing the HAS_FREE_FLAG within pycore_opcode_metadata.h and has the HAS_LOCAL_FLAG set, although it only access freevars not locals, this leads to incorrect behaviour with dis.hasfree().

LOAD_CLOSURE has the same incorrect flags.

This behavior is correct in python3.12, in python3.13 only LOAD_CLOSURE is missing the correct flags.

from the docs:

dis.hasfree():

Sequence of bytecodes that access a free (closure) variable. ‘free’ in this context refers to names in the current scope that are referenced by inner scopes or names in outer scopes that are referenced from this scope. It does not include references to global or builtin scopes.

Minimal Example

import dis

for instr in dis.hasfree:
    print(dis.opname[instr])

Expected Behavior:

DELETE_DEREF
LOAD_CLOSURE
LOAD_DEREF
LOAD_FROM_DICT_OR_DEREF
MAKE_CELL
STORE_DEREF

Actual Behavior:

DELETE_DEREF
LOAD_FROM_DICT_OR_DEREF
MAKE_CELL
STORE_DEREF

CPython versions tested on:

3.15, 3.14, 3.13, 3.12, Main

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added a commit that references this issue on Jun 11, 2026
  2. added a commit that references this issue on Jul 27, 2026
  3. added a commit that references this issue on Jul 29, 2026
  4. added a commit that references this issue on Aug 14, 2026
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