From e6c07851d4f68d9d88ffe05b77c56ad1870478ad Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 27 Mar 2023 10:55:26 +0200 Subject: [PATCH] fix lint checks --- ereuse_devicehub/ereuse_utils/cli.py | 2 +- ereuse_devicehub/ereuse_utils/cmd.py | 6 ++---- ereuse_devicehub/ereuse_utils/nested_lookup.py | 5 +---- .../ereuse_utils/usb_flash_drive.py | 2 +- ereuse_devicehub/teal/cache.py | 4 ++-- ereuse_devicehub/teal/config.py | 18 ++++++++---------- ereuse_devicehub/teal/teal.py | 14 +++++++------- 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/ereuse_devicehub/ereuse_utils/cli.py b/ereuse_devicehub/ereuse_utils/cli.py index d4df20bf..a86eb4be 100644 --- a/ereuse_devicehub/ereuse_utils/cli.py +++ b/ereuse_devicehub/ereuse_utils/cli.py @@ -192,7 +192,7 @@ class Line(tqdm): def error_message(self, *args): self._error_message = args - def close(self): + def close(self): # noqa: C901 """ Cleanup and (if leave=False) close the progressbar. """ diff --git a/ereuse_devicehub/ereuse_utils/cmd.py b/ereuse_devicehub/ereuse_utils/cmd.py index 2f03807f..1f1262f3 100644 --- a/ereuse_devicehub/ereuse_utils/cmd.py +++ b/ereuse_devicehub/ereuse_utils/cmd.py @@ -1,6 +1,6 @@ import subprocess from contextlib import suppress -from typing import Any, Set, TextIO +from typing import Any, Set from ereuse_devicehub.ereuse_utils import text @@ -96,9 +96,7 @@ class ProgressiveCmd: self.conn = conn = subprocess.Popen( self.cmd, universal_newlines=True, stderr=subprocess.PIPE, stdout=stdout ) - self.out = ( - conn.stdout if stdout == subprocess.PIPE else conn.stderr - ) # type: TextIO + self.out = conn.stdout if stdout == subprocess.PIPE else conn.stderr self._callback = callback self.last_update_percentage = 0 self.percentage = 0 diff --git a/ereuse_devicehub/ereuse_utils/nested_lookup.py b/ereuse_devicehub/ereuse_utils/nested_lookup.py index f2a99bc9..805543aa 100644 --- a/ereuse_devicehub/ereuse_utils/nested_lookup.py +++ b/ereuse_devicehub/ereuse_utils/nested_lookup.py @@ -1,6 +1,3 @@ -from typing import Generator - - class NestedLookup: @staticmethod def __new__(cls, document, references, operation): @@ -38,7 +35,7 @@ class NestedLookup: return key_value_containing_value @staticmethod - def _nested_lookup(document, references, operation): + def _nested_lookup(document, references, operation): # noqa: C901 """Lookup a key in a nested document, yield a value""" if isinstance(document, list): for d in document: diff --git a/ereuse_devicehub/ereuse_utils/usb_flash_drive.py b/ereuse_devicehub/ereuse_utils/usb_flash_drive.py index 6d878b0b..444de53d 100644 --- a/ereuse_devicehub/ereuse_utils/usb_flash_drive.py +++ b/ereuse_devicehub/ereuse_utils/usb_flash_drive.py @@ -5,7 +5,7 @@ from usb import CLASS_MASS_STORAGE from ereuse_devicehub.ereuse_utils.naming import Naming -def plugged_usbs(multiple=True) -> map or dict: +def plugged_usbs(multiple=True) -> map or dict: # noqa: C901 """ Gets the plugged-in USB Flash drives (pen-drives). diff --git a/ereuse_devicehub/teal/cache.py b/ereuse_devicehub/teal/cache.py index b6b59566..e8683ee3 100644 --- a/ereuse_devicehub/teal/cache.py +++ b/ereuse_devicehub/teal/cache.py @@ -1,7 +1,7 @@ import datetime from functools import wraps -from flask import Response, make_response +from flask import make_response def cache(expires: datetime.timedelta = None): @@ -18,7 +18,7 @@ def cache(expires: datetime.timedelta = None): def cache_decorator(view): @wraps(view) def cache_func(*args, **kwargs): - r = make_response(view(*args, **kwargs)) # type: Response + r = make_response(view(*args, **kwargs)) r.expires = datetime.datetime.now(datetime.timezone.utc) + expires r.cache_control.public = True return r diff --git a/ereuse_devicehub/teal/config.py b/ereuse_devicehub/teal/config.py index 60500d1b..46cac145 100644 --- a/ereuse_devicehub/teal/config.py +++ b/ereuse_devicehub/teal/config.py @@ -1,5 +1,3 @@ -from typing import Dict, Set, Type - from boltons.typeutils import issubclass from ereuse_devicehub.teal.resource import Resource @@ -12,16 +10,16 @@ class Config: Subclass and set here your config values. """ - RESOURCE_DEFINITIONS = set() # type: Set[Type[Resource]] + RESOURCE_DEFINITIONS = set() """ A list of resource definitions to load. """ - SQLALCHEMY_DATABASE_URI = None # type: str + SQLALCHEMY_DATABASE_URI = None """ The access to the main Database. """ - SQLALCHEMY_BINDS = {} # type: Dict[str, str] + SQLALCHEMY_BINDS = {} """ Optional extra databases. See `here `_ how bind your models to different @@ -29,11 +27,11 @@ class Config: """ SQLALCHEMY_TRACK_MODIFICATIONS = False """ - Disables flask-sqlalchemy notification system. + Disables flask-sqlalchemy notification system. Save resources and hides a warning by flask-sqlalchemy itself. - + See `this answer in Stackoverflow for more info - `_. + `_. """ API_DOC_CONFIG_TITLE = 'Teal' @@ -47,7 +45,7 @@ class Config: API_DOC_CLASS_DISCRIMINATOR = None """ Configuration options for the api docs class definitions. - + You can pass any `schema definition `_ prefiex by ``API_DOC_CLASS_`` like in the example above. @@ -57,7 +55,7 @@ class Config: CORS_EXPOSE_HEADERS = 'Authorization' CORS_ALLOW_HEADERS = 'Content-Type', 'Authorization' """ - Configuration for CORS. See the options you can pass by in `Flask-Cors + Configuration for CORS. See the options you can pass by in `Flask-Cors `_, exactly in **Parameters**, like the ones above. """ diff --git a/ereuse_devicehub/teal/teal.py b/ereuse_devicehub/teal/teal.py index 6acf33c1..4cffab9f 100644 --- a/ereuse_devicehub/teal/teal.py +++ b/ereuse_devicehub/teal/teal.py @@ -1,19 +1,19 @@ import inspect -from typing import Dict, Type +from typing import Type import click_spinner -import ereuse_devicehub.ereuse_utils import flask_cors from anytree import Node from apispec import APISpec from click import option -from ereuse_devicehub.ereuse_utils import ensure_utf8 from flask import Flask, jsonify from flask.globals import _app_ctx_stack from flask_sqlalchemy import SQLAlchemy from marshmallow import ValidationError from werkzeug.exceptions import HTTPException, UnprocessableEntity +import ereuse_devicehub.ereuse_utils +from ereuse_devicehub.ereuse_utils import ensure_utf8 from ereuse_devicehub.teal.auth import Auth from ereuse_devicehub.teal.cli import TealCliRunner from ereuse_devicehub.teal.client import Client @@ -122,17 +122,17 @@ class Teal(Flask): # noinspection PyAttributeOutsideInit def load_resources(self): - self.resources = {} # type: Dict[str, Resource] + self.resources = {} """ The resources definitions loaded on this App, referenced by their type name. """ - self.tree = {} # type: Dict[str, Node] + self.tree = {} """ - A tree representing the hierarchy of the instances of + A tree representing the hierarchy of the instances of ResourceDefinitions. ResourceDefinitions use these nodes to traverse their hierarchy. - + Do not use the normal python class hierarchy as it is global, thus unreliable if you run different apps with different schemas (for example, an extension that is only added on the