[CHORE] update mypy and new issues (#1892)

* [CHORE] update mypy and new issues

lnbits/cache.py:21: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/extension_manager.py:210: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/db.py:110: error: Only instance methods can be decorated with @property  [misc]
lnbits/tasks.py:152: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/tasks.py:171: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/core/services.py:520: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/app.py:520: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/app.py:525: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
lnbits/app.py:532: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]

* fix db.py
* fix mypy notes, type were not needed
This commit is contained in:
dni ⚡
2023-08-23 21:24:54 +02:00
committed by GitHub
parent b0ad47b69b
commit fe88320f08
8 changed files with 54 additions and 47 deletions
+3 -3
View File
@@ -518,19 +518,19 @@ def configure_logger() -> None:
class Formatter:
def __init__(self):
self.padding = 0
self.minimal_fmt: str = (
self.minimal_fmt = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SS}</green> | <level>{level}</level> | "
"<level>{message}</level>\n"
)
if settings.debug:
self.fmt: str = (
self.fmt = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SS}</green> | "
"<level>{level: <4}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> | "
"<level>{message}</level>\n"
)
else:
self.fmt: str = self.minimal_fmt
self.fmt = self.minimal_fmt
def format(self, record):
function = "{function}".format(**record)
+1 -1
View File
@@ -17,7 +17,7 @@ class Cache:
Small caching utility providing simple get/set interface (very much like redis)
"""
def __init__(self):
def __init__(self) -> None:
self._values: dict[Any, Cached] = {}
def get(self, key: str, default=None) -> Optional[Any]:
+1 -1
View File
@@ -516,7 +516,7 @@ async def init_admin_settings(super_user: Optional[str] = None) -> SuperSettings
class WebsocketConnectionManager:
def __init__(self):
def __init__(self) -> None:
self.active_connections: List[WebSocket] = []
async def connect(self, websocket: WebSocket, item_id: str):
+12 -9
View File
@@ -59,6 +59,15 @@ else:
)
def compat_timestamp_placeholder():
if DB_TYPE == POSTGRES:
return "to_timestamp(?)"
elif DB_TYPE == COCKROACH:
return "cast(? AS timestamp)"
else:
return "?"
class Compat:
type: Optional[str] = "<inherited>"
schema: Optional[str] = "<inherited>"
@@ -107,15 +116,9 @@ class Compat:
return "BIGINT"
return "INT"
@classmethod
@property
def timestamp_placeholder(cls):
if DB_TYPE == POSTGRES:
return "to_timestamp(?)"
elif DB_TYPE == COCKROACH:
return "cast(? AS timestamp)"
else:
return "?"
def timestamp_placeholder(self) -> str:
return compat_timestamp_placeholder()
class Connection(Compat):
@@ -402,7 +405,7 @@ class Filter(BaseModel, Generic[TFilterModel]):
@property
def statement(self):
if self.model and self.model.__fields__[self.field].type_ == datetime.datetime:
placeholder = Compat.timestamp_placeholder
placeholder = compat_timestamp_placeholder()
else:
placeholder = "?"
if self.op in (Operator.INCLUDE, Operator.EXCLUDE):
+1 -1
View File
@@ -204,7 +204,7 @@ class Extension(NamedTuple):
class ExtensionManager:
def __init__(self):
def __init__(self) -> None:
p = Path(settings.lnbits_path, "extensions")
Path(p).mkdir(parents=True, exist_ok=True)
self._extension_folders: List[Path] = [f for f in p.iterdir() if f.is_dir()]
+2 -2
View File
@@ -149,7 +149,7 @@ async def check_pending_payments():
logger.info(
f"Task: checking all pending payments (incoming={incoming}, outgoing={outgoing}) of last 15 days"
)
start_time: float = time.time()
start_time = time.time()
pending_payments = await get_payments(
since=(int(time.time()) - 60 * 60 * 24 * 15), # 15 days ago
complete=False,
@@ -168,7 +168,7 @@ async def check_pending_payments():
# we delete expired invoices once upon the first pending check
if incoming:
logger.debug("Task: deleting all expired invoices")
start_time: float = time.time()
start_time = time.time()
await delete_expired_invoices(conn=conn)
logger.info(
f"Task: expired invoice deletion finished (took {time.time() - start_time:0.3f} s)"