-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
🐛 Use inspect
to determine whether the AnyIO version supports abandon_on_cancel
#224
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
#202 introduces an issue on py38 and py39 with an earlier version of
importlib.metadata
not detecting versions in certain virtual environments. It also uses string comparisons:This PR addresses the issue by using
inspect
to determine anyio's supported kwargs for therun_sync
method.