stubtest: error if an attribute is a read-only property at runtime, but isn't read-only in the stub #12291
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.
Description
This PR proposes adding checks to stubtest so that it raises an error if a variable is annotated as being writeable in the stub, but is a read-only property at runtime.
New errors reported by stubtest with this patch applied, when checking typeshed
0; however, this patch was used to prepare the following PR, fixing roughly 50 hits:
Things I tried, which ultimately proved unfruitful
types.GetSetDescriptorType
. Unfortunately, it is much harder to accurately determine whether or not an instance ofGetSetDescriptorType
is a read-only data descriptor, or a read-write data descriptor. (All instances ofGetSetDescriptorType
have a__set__
method, but many of these__set__
methods raiseAttributeError
. Whereas with properties you can do a simpleif prop.fset is None
check, there's no equivalent test forGetSetDescriptor
s.)Test Plan
Four FiveFour new test cases added, one modified.cc. @hauntsaninja