-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix Stubgen's behavior for Instance Variables in C extensions #12524
Merged
JelleZijlstra
merged 4 commits into
python:master
from
shubz1998:fix_stubgen_issue#12150
Apr 11, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Since stubs for special dunder attributes is not expected to be generated, we remove these from the test files.
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.
But we had tests explicitly adding them, so I'd like to make sure these aren't important for pybind11 users.
@sizmailov added these tests in #9903; could you comment on whether removing these attributes from the docs is desirable?
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 agree, annotation of most of dunder attributes makes a little sense and probably utilized only by few people if any, but I cannot speak for whole pybind11 community.
At the time I've added all the attributes to test just because it was generated by the stubgen and I saw no harm in leaving them.
It looks like dunder attributes hiding is orthogonal to the objectives of #12150.
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 agree on this, I had added this change to be in-line with stub generation logic for python files where we ignore special dunder methods (Ref).
We can also choose to not ignore dunder methods in
generate_c_property_stub
, in that case, we would have to update the below two tests since these will now generate stubs for dunder attributes:test_generate_c_type_stub_variable_type_annotation
AssertionError: ['class C(KeyError):', ' __weakref__: Any'] != ['class C(KeyError): ...']
test_generate_c_type_inheritance
AssertionError: ['class C:', ' x: ClassVar[int] = ...', ' __dict__: Any', ' __weakref__: Any'] != ['class C:', ' x: ClassVar[int] = ...']
@sizmailov Let me know if this sounds fine to you and I would then go ahead with the change.
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 your change is OK as is. It is definitely an improvement.
My perception is that
stubgen
is still in the0.x
release state, therefore minor "breaking" changes are totally fine.Last time I checked,
stubgen
had little or no configuration options, which results in many hardcoded decisions such as "no dunder attributes". But this problem is definitely out of the scope of this PR.