Skip to content

PEP 795: Deep Immutability in Python #4468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TobiasWrigstad
Copy link

@TobiasWrigstad TobiasWrigstad commented Jun 19, 2025

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Rationale
    • Specification
    • Backwards Compatibility
    • Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

📚 Documentation preview 📚: https://pep-previews--4468.org.readthedocs.build/

@TobiasWrigstad TobiasWrigstad requested a review from a team as a code owner June 19, 2025 06:16
@python-cla-bot
Copy link

python-cla-bot bot commented Jun 19, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@TobiasWrigstad TobiasWrigstad force-pushed the pep795 branch 3 times, most recently from b2bf4aa to 7cedb55 Compare June 19, 2025 06:38
@AA-Turner AA-Turner changed the title PEP 795: Add deep immutability to Python PEP 795: Deep Immutability in Python Jun 19, 2025
@AA-Turner AA-Turner added the new-pep A new draft PEP submitted for initial review label Jun 19, 2025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a programmatic/text source that this file was created from? If so, it would be useful to include that, and also consider using an SVG file rather than a PNG.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. We followed PEP12 which says:

peps/peps/pep-0012.rst

Lines 604 to 605 in b5ae2b1

Currently, SVG must be avoided due to compatibility issues with the
PEP build system.

Maybe this is outdated instructions?

Currently the file was extracted from Keynote which is macOS-only. We could redraw this in a more accessible format perhaps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can now support & prefer SVG files. If Keynote will export an SVG, that should be fine? I had wondered if you'd used e.g. TikZ or graphviz to make the image.

@AA-Turner
Copy link
Member

Please avoid force pushing, we squash-merge all PRs.

@hugovk
Copy link
Member

hugovk commented Jun 19, 2025

For the next PEP, please wait until the initial PR is merged before opening the PEP discussion, because we want to share the official peps.python.org URL and not the PR preview that will be deleted at some POINT. (Pre-PEP discussions can be opened at any time.)

And especially please wait until the sponsor had confirmed sponsorship, as we the PEP number only gets officially assigned then and it can cause confusion to re-assign numbers later.

Please see PEP 1 for more details.

https://peps.python.org/pep-0001/#submitting-a-pep

Thank you!

Co-authored-by: Michael Droettboom <mdboom@gmail.com>
=============

Note: our current prototype implementation was authored on-top of
Python 3.12. To avoid blocking on rebasing on 3.14 to force
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be for 3.15 at this point.

themselves using ``register_freezable(type)``. Example:

.. code-block:: Python

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add a C API function for this too.

x = 0
def foo(a = False):
nonlocal x
if a:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if a:
if a:

single reference count could be used to track the lifetimes of
all the objects in such a strongly connected component (SCC).

We plan to extend the freeze logic with a SCC analysis that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We plan to extend the freeze logic with a SCC analysis that
We plan to extend the freeze logic with an SCC analysis that

``ob_tid`` would allow for standard mutable thread local objects to
remain the fast path, and is our preferred alternative.

The extensions use use SCC calculations to detect cycles in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The extensions use use SCC calculations to detect cycles in
The extensions to use SCC calculations to detect cycles in


3. The type ``NotFreezable`` which is an empty type which cannot be made immutable and can be used as a super class to classes whose instances should not be possible to freeze

4. The type ``NotFreezableError`` which is raised on an attempt to mutate an immutable object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this for an attempt to freeze and unfreezable object? Below, it says it raises a TypeError when trying to mutate an immutable object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-pep A new draft PEP submitted for initial review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants