Skip to content
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

Move asyncio imports and update docs #553

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,25 @@ default values that you don't want to specify. It is also important to remember
to change the separator if you want to pass `-` as an argument.


##### Async Functions

Fire supports calling async functions too. Here's a simple example.

```python
import asyncio

async def count_to_ten():
for i in range(1, 11):
await asyncio.sleep(1)
print(i)

if __name__ == '__main__':
fire.Fire(count_to_ten)
```

Whenever fire encounters a coroutine function, it runs it, blocking until it completes.


### Argument Parsing

The types of the arguments are determined by their values, rather than by the
Expand Down
3 changes: 1 addition & 2 deletions fire/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def main(argv):
--trace: Get the Fire Trace for the command.
"""

import asyncio
import inspect
import json
import os
Expand All @@ -68,8 +69,6 @@ def main(argv):
from fire import value_types
from fire.console import console_io

import asyncio # pylint: disable=import-error,g-import-not-at-top # pytype: disable=import-error


def Fire(component=None, command=None, name=None, serialize=None):
"""This function, Fire, is the main entrypoint for Python Fire.
Expand Down
3 changes: 1 addition & 2 deletions fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

"""Inspection utility functions for Python Fire."""

import asyncio
import inspect
import sys
import types

from fire import docstrings

import asyncio # pylint: disable=import-error,g-import-not-at-top # pytype: disable=import-error


class FullArgSpec(object):
"""The arguments of a function, as in Python 3's inspect.FullArgSpec."""
Expand Down