GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Code object creation (const interning) can mutate tuples · Issue #121954 · python/cpython

Code object creation (const interning) can mutate tuples #121954

New issue
Copy link
New issue
Copy link
Open
Open
Code object creation (const interning) can mutate tuples#121954
Copy link
Assignees
encukou
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@encukou
encukou
opened on Jul 18, 2024
Issue body actions

In #121863 (comment), Mark suspected something is off in const interning for code objects. Indeed, there is. For example:

# a bit of setup
import sys
interned = sys.intern("foobar")
def f():
    var = "foobar"

# my_tuple = (None, 'foobar'), but with an un-interned string
my_tuple = (None, str(b'foobar', 'ascii'))  

print(id(my_tuple), id(my_tuple[1]))

# pass my_tuple as an input argument for a new code object
f.__code__.replace(co_consts=my_tuple)

# there's now a different object in the tuple!
print(id(my_tuple), id(my_tuple[1]))

I'm working on a change to:

  • create new tuples instead of mutating old ones
  • intern more strings before passing them to PyCode constructors, so that we usually don't need to create new tuples

Linked PRs

  • gh-121954: Don't mutate tuples in _PyCode_New #122180

Activity

  1. encukou
    self-assigned this
    on Jul 18, 2024
  2. encukou
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @encukou
    encukou

Labels

type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.