-
Notifications
You must be signed in to change notification settings - Fork 96
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
base: master
Are you sure you want to change the base?
Conversation
grpclib/client.py
Outdated
if loop is None: | ||
try: | ||
self._loop = asyncio.get_event_loop() | ||
except RuntimeError: |
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.
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.
grpclib/client.py
Outdated
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 |
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.
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.
requirements/test_314.txt
Outdated
@@ -0,0 +1,20 @@ | |||
# This file was autogenerated by uv via the following command: |
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.
Have you tried to regenerate all requirements files instead of introducing new test_314.txt
file?
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.
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.
grpclib/events.py
Outdated
annotationlib = None | ||
|
||
|
||
def _get_annotations(params: Dict[str, Any]) -> Dict[str, Any]: |
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.
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.
With 3.14, the
__annotations__
are no longer inparams
when using a metaclass. This PR fixes this issue by usingannotationlib
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.