Change the spec for class access of Self variables #2148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have tried to create a first draft for disallowing access to variables through the class object containing Self, as discussed here.
The general reception of this proposed change was pretty positive, but I guess we are all not sure how this rule should be worded.
The by far biggest issue is that I write:
where "contains an occurrence of Self" is according to Eric a bit of a new concept. I guess I understand that this is not well defined in the glossary or anywhere else and can of course be used for other things as well. I have tried to skim the Spec and found the following usages in the spec:
Anyor another gradual form.Self. SupportingSelfThere's also two times where "in" is used:
Selfin staticmethods.Selfdoes not add muchSelfin metaclasses.Selfconsistently refers to theI have not found other language about this. I have tried to search for "depends on", "references", "mentions", "introduces" and none of them are used.
However I feel like this concept is often talked in almost implicit ways about TypeVars/Self. For example in the chapter "Type Parameters as Parameters to Generics" (talks about
T1 = TypeVar("T2", default=list[T1])):I feel like there's a couple of other places where different words are used, but it's not like this concept is new.
Please let me know what you all think. I'm happy to improve the wording.