From 1aa72a66acd4e9dc421deb5523a429f9f4519421 Mon Sep 17 00:00:00 2001 From: David Bieber Date: Sat, 16 Aug 2025 16:42:23 -0400 Subject: [PATCH 1/4] Add Python 3.13 and 3.14 checking in build workflow --- .github/workflows/build.yml | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75a687f3..6b9d1eae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: ["macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13.0-rc.2"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14.0-rc.2"] include: - {os: "ubuntu-22.04", python-version: "3.7"} diff --git a/pyproject.toml b/pyproject.toml index eccee91b..554407d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Operating System :: OS Independent", "Operating System :: POSIX", "Operating System :: MacOS", From 9f0b88e7ddb1f7dbfae1d10c3a8c97f77e89f291 Mon Sep 17 00:00:00 2001 From: David Bieber Date: Sat, 16 Aug 2025 16:55:08 -0400 Subject: [PATCH 2/4] Support running coroutines even when there is no existing event loop --- fire/core.py | 10 ++++++++-- fire/inspectutils.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fire/core.py b/fire/core.py index 32e0e9cc..8e23e76b 100644 --- a/fire/core.py +++ b/fire/core.py @@ -678,8 +678,14 @@ def _CallAndUpdateTrace(component, args, component_trace, treatment='class', # Call the function. if inspectutils.IsCoroutineFunction(fn): - loop = asyncio.get_event_loop() - component = loop.run_until_complete(fn(*varargs, **kwargs)) + try: + loop = asyncio.get_running_loop() + except RuntimeError: + # No event loop running, create a new one + component = asyncio.run(fn(*varargs, **kwargs)) + else: + # Event loop is already running + component = loop.run_until_complete(fn(*varargs, **kwargs)) else: component = fn(*varargs, **kwargs) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index 0a79d24b..70f234ed 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -345,6 +345,6 @@ def GetClassAttrsDict(component): def IsCoroutineFunction(fn): try: - return asyncio.iscoroutinefunction(fn) + return inspect.iscoroutinefunction(fn) except: # pylint: disable=bare-except return False From 74a0f5e868ddf5dc9fd7ceeb7dd08d63f872a7e4 Mon Sep 17 00:00:00 2001 From: David Bieber Date: Sat, 16 Aug 2025 16:59:49 -0400 Subject: [PATCH 3/4] Remove unused import --- fire/inspectutils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index 70f234ed..17508e30 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -14,7 +14,6 @@ """Inspection utility functions for Python Fire.""" -import asyncio import inspect import sys import types From aa176944d2ed76d4ca0783c63892f48badb80f3c Mon Sep 17 00:00:00 2001 From: David Bieber Date: Sat, 16 Aug 2025 17:20:25 -0400 Subject: [PATCH 4/4] Add lint directive --- fire/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fire/parser.py b/fire/parser.py index 1a4f7d9b..a335cc2c 100644 --- a/fire/parser.py +++ b/fire/parser.py @@ -19,7 +19,7 @@ import sys if sys.version_info[0:2] < (3, 8): - _StrNode = ast.Str # type: ignore # deprecated but needed for Python < 3.8 + _StrNode = ast.Str # type: ignore # pylint: disable=no-member # deprecated but needed for Python < 3.8 else: _StrNode = ast.Constant