From c498f949cce50206d16046c104260cb7e289b344 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 25 Sep 2020 16:47:55 +0200 Subject: [PATCH] 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. --- contrib/pyln-testing/Makefile | 2 +- contrib/pyln-testing/pyln/testing/btcproxy.py | 8 +++---- contrib/pyln-testing/pyln/testing/db.py | 21 ++++++++++--------- contrib/pyln-testing/pyln/testing/utils.py | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/contrib/pyln-testing/Makefile b/contrib/pyln-testing/Makefile index f0062b531..3ad8059ba 100644 --- a/contrib/pyln-testing/Makefile +++ b/contrib/pyln-testing/Makefile @@ -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 diff --git a/contrib/pyln-testing/pyln/testing/btcproxy.py b/contrib/pyln-testing/pyln/testing/btcproxy.py index 5fa45874a..5b7e3537a 100644 --- a/contrib/pyln-testing/pyln/testing/btcproxy.py +++ b/contrib/pyln-testing/pyln/testing/btcproxy.py @@ -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 diff --git a/contrib/pyln-testing/pyln/testing/db.py b/contrib/pyln-testing/pyln/testing/db.py index 804309981..7024b5eeb 100644 --- a/contrib/pyln-testing/pyln/testing/db.py +++ b/contrib/pyln-testing/pyln/testing/db.py @@ -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 diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 2c86af667..0cc34de15 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -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