Skip to content

Wrap partial in enum.member for Python 3.11+ - #238

Open
mweinelt wants to merge 3 commits into
JeffLIrion:masterfrom
mweinelt:python3.13-compat
Open

Wrap partial in enum.member for Python 3.11+#238
mweinelt wants to merge 3 commits into
JeffLIrion:masterfrom
mweinelt:python3.13-compat

Conversation

@mweinelt

@mweinelt mweinelt commented Jan 4, 2025

Copy link
Copy Markdown

Fixes the following warning and the resulting test errors on Python 3.13.

functools.partial will be a method descriptor in future Python versions;
wrap it in enum.member() if you want to preserve the old behavior

Fixes the following warning and the resulting test errors on Python 3.13.

> functools.partial will be a method descriptor in future Python versions;
> wrap it in enum.member() if you want to preserve the old behavior
@mweinelt

mweinelt commented Jan 4, 2025

Copy link
Copy Markdown
Author

The remaining error seems to be

RuntimeWarning("coroutine method 'aclose' of 'AdbDeviceAsync.streaming_shell' was never awaited")

python/cpython#117536

@FliegendeWurst

Copy link
Copy Markdown

That warning can be worked around by adding await asyncio.sleep(0), apparently. It would be better to close the stream explicitly of course.

Comment thread .github/workflows/python-package.yml Outdated
@mweinelt

mweinelt commented Jan 7, 2025

Copy link
Copy Markdown
Author

That warning can be worked around by adding await asyncio.sleep(0), apparently. It would be better to close the stream explicitly of course.

I tried the following change, but it didn't help.

diff --git a/adb_shell/adb_device_async.py b/adb_shell/adb_device_async.py
index 84ce523..c8cc170 100644
--- a/adb_shell/adb_device_async.py
+++ b/adb_shell/adb_device_async.py
@@ -904,8 +904,12 @@ class AdbDeviceAsync(object):
         if not self.available:
             raise exceptions.AdbConnectionError("ADB command not sent because a connection to the device has not been established.  (Did you call `AdbDeviceAsync.connect()`?)")
 
-        async for line in self._streaming_service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, decode):
-            yield line
+        agen = self._streaming_service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, decode)
+        try:
+            async for line in agen:
+                yield line
+        finally:
+            await agen.aclose()
 
     # ======================================================================= #
     #                                                                         #

3.13 is the latest version and 3.7/3.8 have both reached EOL..
If they are caught and we raise RuntimeError those warnings will not be
visible anymore, which makes noticing and fixing them so much harder.
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