Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixes annotations and tests for python 3.14 #208

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

Open
thomasjpfan wants to merge 21 commits into vmagamedov:master
base: master
Choose a base branch
Loading
from thomasjpfan:fix_annotatinos_py314

Conversation

@thomasjpfan
Copy link

@thomasjpfan thomasjpfan commented Oct 10, 2025
edited
Loading

With 3.14, the __annotations__ are no longer in params when using a metaclass. This PR fixes this issue by using annotationlib for Python 3.14 to get the annotations.

For details see: https://docs.python.org/3.14/library/annotationlib.html

I also need to generate another Python 3.14 requirements file to pull in the changes from pytest-asyncio that is compatible with 3.14.

@thomasjpfan thomasjpfan changed the title (削除) Fixes annotations for python 3.14 (削除ここまで) (追記) Fixes annotations and tests for python 3.14 (追記ここまで) Oct 11, 2025
if loop is None:
try:
self._loop = asyncio.get_event_loop()
except RuntimeError:
Copy link
Owner

@vmagamedov vmagamedov Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeError is a generic exception which might be raised for many reasons. It might be better to check the Python version instead of relying on exceptions.

except RuntimeError:
# In Python 3.14, if there is no event loop, then
# `get_event_loop` will raise an error and not create an
# event loop. To reproduce pre 3.14 behavior, we'll create
Copy link
Owner

@vmagamedov vmagamedov Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grpclib is a library, not a framework, IMO we can't create an event loop on our own, and then make it private. So it must be ok that error will be thrown if there is no event loop in the current context, then it is user's responsibility to create one.

@@ -0,0 +1,20 @@
# This file was autogenerated by uv via the following command:
Copy link
Owner

@vmagamedov vmagamedov Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried to regenerate all requirements files instead of introducing new test_314.txt file?

Copy link
Author

@thomasjpfan thomasjpfan Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but I did not come up with a way to get pip-compile to auto-generate a single file that works with 3.8 and newer versions.

I did another attempt to generate one for 3.9 and use that for Python>=3.9, but it was not compatible with 3.13.

Another approach is to generate a 3.14 file with ; python_version >= "3.14, add ; python_version < "3.14" to the current test.txt, and combine the two files. It feels kind of hacky tho.

Copy link
Author

@thomasjpfan thomasjpfan Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you okay with generating a new test_314.txt for Python 3.14?

annotationlib = None


def _get_annotations(params: Dict[str, Any]) -> Dict[str, Any]:
Copy link
Owner

@vmagamedov vmagamedov Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to have _compat module: v0.3.2/grpclib/_compat.py

It makes sense to create such module again and move compatibility code there.

thomasjpfan reacted with thumbs up emoji
Copy link
Author

@thomasjpfan thomasjpfan Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! I moved this logic to a _compat.py file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vmagamedov vmagamedov vmagamedov left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /