Skip to content

Commit

Permalink
docs: add instructions to generate type hints (#8025)
Browse files Browse the repository at this point in the history
* Add instructions to generate type hints 

Use mypy to generate .pyi files as well. These files are useful for type hinting in IDEs.

* Update python.md

fix lines that got swapped in copy-paste

* remove mypy 

mypy is not a dependency
  • Loading branch information
davisv7 authored Oct 6, 2023
1 parent dce4bb1 commit 80bfd17
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/grpc/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ file in Python before you can use it to communicate with lnd.
3. Install dependencies (googleapis-common-protos is required due to the use of
google/api/annotations.proto)
```shell
lnd $ pip install grpcio grpcio-tools googleapis-common-protos
lnd $ pip install grpcio grpcio-tools googleapis-common-protos mypy-protobuf
```
4. Clone the google api's repository (required due to the use of
google/api/annotations.proto)
Expand All @@ -35,12 +35,11 @@ file in Python before you can use it to communicate with lnd.
```
6. Compile the proto file
```shell
lnd $ python -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. lightning.proto
lnd $ python -m grpc_tools.protoc --proto_path=googleapis:. --mypy_out=. --python_out=. --grpc_python_out=. lightning.proto
```

After following these steps, two files `lightning_pb2.py` and
`lightning_pb2_grpc.py` will be generated. These files will be imported in your
project anytime you use Python gRPC.
After following these steps, three files `lightning_pb2.py`,
`lightning_pb2_grpc.py` and `lightning_pb2.pyi` will be generated. These files will be imported in your project anytime you use Python gRPC.

### Generating RPC modules for subservers

Expand All @@ -50,11 +49,11 @@ generate the python modules for them.
For example, if you want to generate the RPC modules for the `Router` subserver
(located/defined in `routerrpc/router.proto`), you need to run the following two
extra steps (after completing all 6 step described above) to get the
`router_pb2.py` and `router_pb2_grpc.py`:
`router_pb2.py`, `router_pb2_grpc.py` and `router_pb2.pyi`:
```shell
lnd $ curl -o router.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/routerrpc/router.proto
lnd $ python -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. router.proto
lnd $ python -m grpc_tools.protoc --proto_path=googleapis:. --mypy_out=. --python_out=. --grpc_python_out=. router.proto
```
### Imports and Client
Expand Down Expand Up @@ -221,4 +220,4 @@ Here is an example of a working format that allows for use of a reserved word `g
```
args = {'global': True, 'base_fee_msat': 1000, 'fee_rate': 0.000001, 'time_lock_delta': 40}
stub.UpdateChannelPolicy(ln.PolicyUpdateRequest(**args))
```
```

0 comments on commit 80bfd17

Please sign in to comment.