Skip to content

Commit

Permalink
Move asyncio imports and update docs (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbieber authored Sep 20, 2024
1 parent 93b0e32 commit 5b2dadd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit 5b2dadd

Please sign in to comment.