Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PEP 767: Address feedback & open issues #4559

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
Enegg wants to merge 4 commits into python:main
base: main
Choose a base branch
Loading
from Enegg:pep-767
Open

Conversation

@Enegg
Copy link
Contributor

@Enegg Enegg commented Aug 25, 2025
edited
Loading

  • 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"
  • Removed the restrictions on internal mutation of a read-only attribute

📚 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
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.

Enegg reacted with thumbs up emoji
'''''''''''''''''''

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra Awaiting requested review from JelleZijlstra

@carljm carljm Awaiting requested review from carljm carljm is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /