chore: adhere to ruff's C (#2379)

This commit is contained in:
dni ⚡ 2024-04-03 17:56:05 +02:00 committed by GitHub
parent cd66b7d70c
commit e0b7d2f739
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 43 additions and 41 deletions

View file

@ -135,7 +135,7 @@ async def api_uninstall_extension(
) )
# check that other extensions do not depend on this one # check that other extensions do not depend on this one
for valid_ext_id in list(map(lambda e: e.code, get_valid_extensions())): for valid_ext_id in [ext.code for ext in get_valid_extensions()]:
installed_ext = next( installed_ext = next(
(ext for ext in installable_extensions if ext.id == valid_ext_id), None (ext for ext in installable_extensions if ext.id == valid_ext_id), None
) )

View file

@ -113,6 +113,7 @@ async def extensions_install(
except Exception as ex: except Exception as ex:
logger.warning(ex) logger.warning(ex)
installable_exts = [] installable_exts = []
installed_exts_ids = []
try: try:
ext_id = activate or deactivate ext_id = activate or deactivate
@ -137,12 +138,11 @@ async def extensions_install(
ext_id=ext_id, active=activate is not None ext_id=ext_id, active=activate is not None
) )
all_ext_ids = list(map(lambda e: e.code, all_extensions)) all_ext_ids = [ext.code for ext in all_extensions]
inactive_extensions = await get_inactive_extensions() inactive_extensions = await get_inactive_extensions()
db_version = await get_dbversions() db_version = await get_dbversions()
extensions = list( extensions = [
map( {
lambda ext: {
"id": ext.id, "id": ext.id,
"name": ext.name, "name": ext.name,
"icon": ext.icon, "icon": ext.icon,
@ -161,10 +161,9 @@ async def extensions_install(
"installedRelease": ( "installedRelease": (
dict(ext.installed_release) if ext.installed_release else None dict(ext.installed_release) if ext.installed_release else None
), ),
}, }
installable_exts, for ext in installable_exts
) ]
)
# refresh user state. Eg: enabled extensions. # refresh user state. Eg: enabled extensions.
user = await get_user(user.id) or user user = await get_user(user.id) or user

View file

@ -393,7 +393,7 @@ async def subscribe_wallet_invoices(request: Request, wallet: Wallet):
payment: Payment = await payment_queue.get() payment: Payment = await payment_queue.get()
if payment.wallet_id == this_wallet_id: if payment.wallet_id == this_wallet_id:
logger.debug("sse listener: payment received", payment) logger.debug("sse listener: payment received", payment)
yield dict(data=payment.json(), event="payment-received") yield {"data": payment.json(), "event": "payment-received"}
except asyncio.CancelledError: except asyncio.CancelledError:
logger.debug(f"removing listener for wallet {uid}") logger.debug(f"removing listener for wallet {uid}")
except Exception as exc: except Exception as exc:

View file

@ -78,7 +78,7 @@ class InstalledExtensionMiddleware:
"", "",
) )
if "text/html" in [a for a in accept_header.split(",")]: if "text/html" in accept_header.split(","):
return HTMLResponse( return HTMLResponse(
status_code=status_code, status_code=status_code,
content=template_renderer() content=template_renderer()

View file

@ -167,6 +167,8 @@ class LndRestNode(Node):
point: Optional[ChannelPoint] = None, point: Optional[ChannelPoint] = None,
force: bool = False, force: bool = False,
): ):
if short_id:
logger.debug(f"Closing channel with short_id: {short_id}")
if not point: if not point:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, detail="Channel point required" status_code=HTTPStatus.BAD_REQUEST, detail="Channel point required"

View file

@ -10,10 +10,10 @@ from lnbits.settings import set_cli_settings, settings
@click.command( @click.command(
context_settings=dict( context_settings={
ignore_unknown_options=True, "ignore_unknown_options": True,
allow_extra_args=True, "allow_extra_args": True,
) }
) )
@click.option("--port", default=settings.port, help="Port to listen on") @click.option("--port", default=settings.port, help="Port to listen on")
@click.option("--host", default=settings.host, help="Host to run LNBits on") @click.option("--host", default=settings.host, help="Host to run LNBits on")
@ -48,7 +48,7 @@ def main(
# this beautiful beast parses all command line arguments and # this beautiful beast parses all command line arguments and
# passes them to the uvicorn server # passes them to the uvicorn server
d = dict() d = {}
for a in ctx.args: for a in ctx.args:
item = a.split("=") item = a.split("=")
if len(item) > 1: # argument like --key=value if len(item) > 1: # argument like --key=value

View file

@ -31,7 +31,7 @@ from .base import (
class FakeWallet(Wallet): class FakeWallet(Wallet):
queue: asyncio.Queue = asyncio.Queue(0) queue: asyncio.Queue = asyncio.Queue(0)
payment_secrets: Dict[str, str] = dict() payment_secrets: Dict[str, str] = {}
paid_invoices: Set[str] = set() paid_invoices: Set[str] = set()
secret: str = settings.fake_wallet_secret secret: str = settings.fake_wallet_secret
privkey: str = hashlib.pbkdf2_hmac( privkey: str = hashlib.pbkdf2_hmac(

View file

@ -142,7 +142,7 @@ class LndRestWallet(Wallet):
async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse: async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse:
# set the fee limit for the payment # set the fee limit for the payment
lnrpcFeeLimit = dict() lnrpcFeeLimit = {}
lnrpcFeeLimit["fixed_msat"] = f"{fee_limit_msat}" lnrpcFeeLimit["fixed_msat"] = f"{fee_limit_msat}"
try: try:

View file

@ -164,7 +164,8 @@ extend-exclude = [
# W - pycodestyle warnings # W - pycodestyle warnings
# I - isort # I - isort
# A - flake8-builtins # A - flake8-builtins
select = ["F", "E", "W", "I", "A"] # C - mccabe
select = ["F", "E", "W", "I", "A", "C"]
ignore = [] ignore = []
# Allow autofix for all enabled rules (when `--fix`) is provided. # Allow autofix for all enabled rules (when `--fix`) is provided.
@ -179,5 +180,5 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"__init__.py" = ["F401", "F403"] "__init__.py" = ["F401", "F403"]
[tool.ruff.lint.mccabe] [tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10. # TODO: Decrease this to 10.
max-complexity = 10 max-complexity = 16

View file

@ -152,8 +152,8 @@ def migrate_db(file: str, schema: str, exclude_tables: List[str] = []):
def build_insert_query(schema, tableName, columns): def build_insert_query(schema, tableName, columns):
to_columns = ", ".join(map(lambda column: f'"{column[1].lower()}"', columns)) to_columns = ", ".join([f'"{column[1].lower()}"' for column in columns])
values = ", ".join(map(lambda column: to_column_type(column[2]), columns)) values = ", ".join([to_column_type(column[2]) for column in columns])
return f""" return f"""
INSERT INTO {schema}.{tableName}({to_columns}) INSERT INTO {schema}.{tableName}({to_columns})
VALUES ({values}); VALUES ({values});