Skip to content

Conversation

thomasjpfan
Copy link

@thomasjpfan thomasjpfan commented Oct 10, 2025

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

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

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

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

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.

annotationlib = None


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

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants