Skip to content

Commit 5b2dadd

Browse files
authored
Move asyncio imports and update docs (#553)
1 parent 93b0e32 commit 5b2dadd

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

docs/guide.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,25 @@ default values that you don't want to specify. It is also important to remember
589589
to change the separator if you want to pass `-` as an argument.
590590

591591

592+
##### Async Functions
593+
594+
Fire supports calling async functions too. Here's a simple example.
595+
596+
```python
597+
import asyncio
598+
599+
async def count_to_ten():
600+
for i in range(1, 11):
601+
await asyncio.sleep(1)
602+
print(i)
603+
604+
if __name__ == '__main__':
605+
fire.Fire(count_to_ten)
606+
```
607+
608+
Whenever fire encounters a coroutine function, it runs it, blocking until it completes.
609+
610+
592611
### Argument Parsing
593612

594613
The types of the arguments are determined by their values, rather than by the

fire/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def main(argv):
4949
--trace: Get the Fire Trace for the command.
5050
"""
5151

52+
import asyncio
5253
import inspect
5354
import json
5455
import os
@@ -68,8 +69,6 @@ def main(argv):
6869
from fire import value_types
6970
from fire.console import console_io
7071

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

7473
def Fire(component=None, command=None, name=None, serialize=None):
7574
"""This function, Fire, is the main entrypoint for Python Fire.

fire/inspectutils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

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

17+
import asyncio
1718
import inspect
1819
import sys
1920
import types
2021

2122
from fire import docstrings
2223

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

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

0 commit comments

Comments
 (0)