Skip to content

Conversation

Enegg
Copy link
Contributor

@Enegg Enegg commented Aug 25, 2025

  • Added my real name 🫠
  • Updated Post-History
  • Bikeshedded on some of the wording in this PEP
  • Clarified that use of bare ReadOnly is not allowed, and added that to rejected ideas
  • Specified that a protocol's read-only attributes are not accessible from its type (type[Protocol])
  • Closed open issue: "Extending Initialization"

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

Clarify that bare `ReadOnly` is not allowed, and add that to rejected ideas
Specify that `type[Protocol]` does not inherit the protocol's attributes
Close issue: "Extending Initialization"
Bikeshed on some wording
Use my real name
@Enegg Enegg requested a review from carljm as a code owner August 25, 2025 15:31
@@ -176,6 +178,7 @@ It can be used at class-level or within ``__init__`` to mark individual attribut
self.id = id
self.name: ReadOnly[str] = name

Use of bare ``ReadOnly`` (without ``[<type>]``) is not allowed.
Type checkers should error on any attempt to reassign or ``del``\ ete an attribute
Copy link
Member

Choose a reason for hiding this comment

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

The meaning of "reassign" here is not clear. (What is an "assignment" and what is a "reassignment"?)

I think it's clarified below, but maybe we should reference that here.


Instance Attributes
'''''''''''''''''''

Assignment to an instance attribute must be allowed in the following contexts:
Assignment to a read-only instance attribute must be allowed in the following contexts:
Copy link
Member

Choose a reason for hiding this comment

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

I think @oscarbenjamin raised an interesting point in the Discourse thread about this. The effects of ReadOnly as described in this PEP (structural typing and variance of generics) only require for soundness that we disallow external mutation of the attribute. Disallowing internal mutation (within methods of the class) is not required for soundness, and is arguably veering too far into Final territory.

It would simplify this section (and type checker implementations) quite a lot if we just specified that ReadOnly describes the external interface of the attribute, and all internal reassignments of a ReadOnly attribute (within methods of the class) are permitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants