pyln: Add mypy typing exceptions for external dependencies

We don't control them, and starting to write type stubs for them is a
different can of worms.
This commit is contained in:
Christian Decker
2020-09-25 16:47:55 +02:00
committed by Rusty Russell
parent e13c435aca
commit c498f949cc
4 changed files with 19 additions and 18 deletions

View File

@@ -25,7 +25,7 @@ check-pytest:
pytest tests
check-mypy:
mypy --namespace-packages tests pyln
MYPYPATH=$(PYTHONPATH) mypy --namespace-packages tests pyln
$(SDIST_FILE):
python3 setup.py sdist

View File

@@ -1,10 +1,10 @@
""" A bitcoind proxy that allows instrumentation and canned responses
"""
from flask import Flask, request
from bitcoin.rpc import JSONRPCError
from bitcoin.rpc import RawProxy as BitcoinProxy
from cheroot.wsgi import Server
from cheroot.wsgi import PathInfoDispatcher
from bitcoin.rpc import JSONRPCError # type: ignore
from bitcoin.rpc import RawProxy as BitcoinProxy # type: ignore
from cheroot.wsgi import Server # type: ignore
from cheroot.wsgi import PathInfoDispatcher # type: ignore
import decimal
import flask

View File

@@ -1,10 +1,10 @@
from ephemeral_port_reserve import reserve
from ephemeral_port_reserve import reserve # type: ignore
from glob import glob
import itertools
import logging
import os
import psycopg2
import psycopg2 # type: ignore
import random
import re
import shutil
@@ -13,18 +13,19 @@ import sqlite3
import string
import subprocess
import time
from typing import Dict, List, Optional, Union
class Sqlite3Db(object):
def __init__(self, path):
def __init__(self, path: str) -> None:
self.path = path
def get_dsn(self):
def get_dsn(self) -> None:
"""SQLite3 doesn't provide a DSN, resulting in no CLI-option.
"""
return None
def query(self, query):
def query(self, query: str) -> Union[List[Dict[str, Union[int, bytes]]], List[Dict[str, Optional[int]]], List[Dict[str, str]], List[Dict[str, Union[str, int]]], List[Dict[str, int]]]:
orig = os.path.join(self.path)
copy = self.path + ".copy"
shutil.copyfile(orig, copy)
@@ -44,7 +45,7 @@ class Sqlite3Db(object):
db.close()
return result
def execute(self, query):
def execute(self, query: str) -> None:
db = sqlite3.connect(self.path)
c = db.cursor()
c.execute(query)
@@ -91,20 +92,20 @@ class PostgresDb(object):
class SqliteDbProvider(object):
def __init__(self, directory):
def __init__(self, directory: str) -> None:
self.directory = directory
def start(self):
def start(self) -> None:
pass
def get_db(self, node_directory, testname, node_id):
def get_db(self, node_directory: str, testname: str, node_id: int) -> Sqlite3Db:
path = os.path.join(
node_directory,
'lightningd.sqlite3'
)
return Sqlite3Db(path)
def stop(self):
def stop(self) -> None:
pass

View File

@@ -1,10 +1,10 @@
from bitcoin.core import COIN
from bitcoin.rpc import RawProxy as BitcoinProxy
from bitcoin.core import COIN # type: ignore
from bitcoin.rpc import RawProxy as BitcoinProxy # type: ignore
from pyln.client import RpcError
from pyln.testing.btcproxy import BitcoinRpcProxy
from collections import OrderedDict
from decimal import Decimal
from ephemeral_port_reserve import reserve
from ephemeral_port_reserve import reserve # type: ignore
from pyln.client import LightningRpc
from pyln.client import Millisatoshi