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/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..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 @@ -345,6 +344,6 @@ def GetClassAttrsDict(component): def IsCoroutineFunction(fn): try: - return asyncio.iscoroutinefunction(fn) + return inspect.iscoroutinefunction(fn) except: # pylint: disable=bare-except return False 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 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",