-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat: ✨ automatically replace invalid enum expressions with corresponding valid expression & import #196
Conversation
…ding valid expression & import --enum-class-locations shouldn't usually need to be provided now!
This should eliminate the need for enum location specification for most use cases. This PR introduces a bit of guessing to stub generation if the module has two enums with the same class and value names. Depending on the order of traversing the module, the resulting stubs could be different. I suggest the following changes:
|
...ubs/python-3.12/pybind11-master/numpy-array-use-type-var/demo/_bindings/aliases/__init__.pyi
Outdated
Show resolved
Hide resolved
@sizmailov are you planning to drop support for 3.7 at some point? It reached end of life status 5 months ago. I would like it if we did, because I want to use the assignment expression operator ( 3.8's EOL is coming in only 10 months, also. numpy has already dropped support for it in preparation. What are your thoughts about this? |
so that we can detect if an identical enum + field was defined somewhere else: sizmailov#196 (comment)
these were being created from a set, so the test output wasn't matching since the order is not deterministic
I think we should aim for the same versions as pybind11, which is currently 3.6+. So Python 3.7 support would stay for quite a while, for better or worse. |
@sizmailov Okay, I gave it my best effort.
|
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.
Thank you!
The change looks good to me.
Just a couple of doc suggestions.
If you don't mind, I'll publish it as 2.4.1 |
I don't mind! Thank you for reviewing my work! |
Inspired by: #192
I think this feature supersedes the need for
--enum-class-locations
, though I did not remove it here. At least that is my goal. I want this project to be as easy for people to pick up as possible, and this was something I thought should be possible forpybind11_stubgen
to do on behalf of the user.We tweak
RewritePybind11EnumValueRepr
to delayreport_error()
for enum expressions. We remember all of the invalid enum expressions we have seen as we crawl through the module. When we find the definition of a value corresponding to an enum repr, we use it to fix invalid expressions we have seen or will see. If there are still invalid enum expressions left over, wereport_error()
duringfinalize()
.