-
-
Notifications
You must be signed in to change notification settings - Fork 78
🐛 Use inspect to determine whether the AnyIO version supports abandon_on_cancel
#224
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: main
Are you sure you want to change the base?
Conversation
|
This bug affects v0.0.8 (the latest version) only. The PR also contains as prior solution to correctly detect AnyIO package version using We should avoid relying on |
|
@tiangolo I would recommend merging and releasing this in the next version before dropping Python 3.8 support. |
|
This still affects non-venv environments. This should be merged and released, as any packages using this that are installed as part of a system install (or flat package) have to explicitly block v0.0.8 from dependency mapping. |
ffa8ec8 to
7c734f1
Compare
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.
can you check why the check level is failing?
inspect to determine whether the AnyIO version supports abandon_on_cancel
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.
Hi @Stealthii, thanks for the contribution, and apologies for the delay in reviewing this!
Comparing the ANYIO_VERSION with a string comparison is definitely a bug, and something we'll make sure to avoid in the future.
I think it makes sense to use a direct inspect call to check the availability of the correct argument. All the changes in this PR look good to me, and it even removes some duplicate code which is great 💯
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! 🚀
There's one small issue with the current implementation, the check for abandon_on_cancel will be executed every time run_sync is called. With something closer to the previous implementation (with some duplicated code) the check is run only once when declaring the function, but after that, one of the two versions of the function will be the only one declared and executed.
Maybe we could move the if statement to the position where the previous (and problematic) check was.
a947837 to
4223411
Compare
importlib.metadata in Python 3.10 had improved handling of certain virtual environments. This change addresses the issue with some venv environments not returning a version string for AnyIO.
This should keep type checkers happy that aren't running code.
This ensures the check is only performed once on import, whilst retaining a static function definition.
4223411 to
0227077
Compare
|
Thanks @Stealthii for the work (and the patience).
I'm not sure I fully got this part 😅 But to simplify, I would leave the code almost as it currently is before this PR, trading: if ANYIO_VERSION >= "4.1.0":for: if RUN_SYNC_AOC:Don't worry too much about the commit history, in the end I would squash and merge. |
|
@tiangolo: You're right - the code duplication is useful in this case because it prevents the check being run every time the function is executed. I've restored the code to have the same structure as current |
The original reason I moved the check into a constant (once when importing the module), and had
Checking a boolean isn't that expensive honestly. |
|
This is still an issue, and with the recently released 0.0.9 having the bug too, it's causing the need for build systems to blocklist both 0.0.8 and 0.0.9 now from dependency constraints. |
#202 introduces an issue on py38 and py39 with an earlier version of
importlib.metadatanot detecting versions in certain virtual environments. It also uses string comparisons:This PR addresses the issue by using
inspectto determine anyio's supported kwargs for therun_syncmethod.