-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add typing and collections.abc module prefix #5663
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: master
Are you sure you want to change the base?
Conversation
These type hints are invalid in Python 3.8. Add `typing.` prefix to remove ambiguity.
The tests need updating to reflect these changes. |
@InvincibleRMC, thoughts? |
I think this is a good idea. This was discussed a little in and around #5566 (comment). Adding the module prefix will allow users to create their own |
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.
Looks good to me, but do we actually still want to support Python 3.8?
Python 3.8 EOL was 2024-10-07
include/pybind11/detail/common.h
Outdated
@@ -239,6 +239,27 @@ | |||
# define PYBIND11_SUBINTERPRETER_SUPPORT | |||
#endif | |||
|
|||
// 3.9 Compatibility | |||
#if 0x03090000 <= PY_VERSION_HEX | |||
# define PYBIND11_ITERABLE_TYPE_HINT "collections.abc.Iterable" |
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.
Suggestion to make these
PYBIND11_TYPE_HINT_...
so they line up nicely and are easier to pin-point.
include/pybind11/detail/common.h
Outdated
@@ -239,6 +239,27 @@ | |||
# define PYBIND11_SUBINTERPRETER_SUPPORT | |||
#endif | |||
|
|||
// 3.9 Compatibility |
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.
// Python 3.9+ Compatibility
?
(The +
is the most important aspect of my suggestion.)
You still have test runners for 3.8 so I assumed you still supported it. |
Me: yes But I'll go with @henryiii's judgement. |
Let's keep it for 3.0. We can drop it for 3.1. |
It's in setup.cfg (or pyproject.toml after #5598) |
I think I am going to scale back this pull request to just adding the module prefix. |
Fixing this issue in Python 3.8 will require updating lots of tests. This can be added in a further pull request.
I have fixed the tests. |
If you want it to go into 3.0, 3.8 needs to work (where "work" is very loosely defined as "not be worse that it is now"). If you are fine to wait till after 3.0 (like a week), then no need to worry about 3.8. I'd personally go for the latter. |
This can wait for 3.1. I have removed the 3.8 compatibility macros and moved the strings inline. |
I don't know why that test is failing |
All tests pass. @gentlegiantJGC do you want to merge this now (looks good to me)? Or wait until after the v3.0.0 release? |
This can't be merged yet because it changes the following which are incompatible with Python 3.8 I decided not to support 3.8 because it would make the codebase more complex for something which is getting removed which felt pointless. |
Sounds good. I'm just curious: What exactly is incompatible? Certain type checkers when running under 3.8? We're not testing that here? Could/should we? |
Aren't these strings? Those are valid at type-check time, just not turning them into non-string annotations at runtime. I think that's not terrible, though? We might even have examples elsewhere? Our annotations are very much not runnable at runtime already. |
Description
Add
typing.
andcollections.abc
prefix to remove ambiguity.Suggested changelog entry: