-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Conversation
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
@@ -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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
ReadOnly
is not allowed, and added that to rejected ideastype[Protocol]
)📚 Documentation preview 📚: https://pep-previews--4559.org.readthedocs.build/