fix: clear the type checker and linter findings
flake8 reported 49 findings and pyright 10, and two of them were real bugs rather than matters of style. The rest were unused imports and four functions over the complexity limit. - Unlock a DOI folder with the id the DOI response carries, rather than an attribute the model does not have, which raised `AttributeError` on every locked DOI folder. - Size the `ls` Size column from the sub-folder on the row rather than from its parent, which pushed the later columns out of line. - Share the path resolution and the destination checks between `cp` and `mv`, and split the recursive download and the `ls` row printing, bringing all four functions under the complexity limit. - Accept a client built without a connection, which `config` and `version` rely on, and report the reason if one is then asked for. - Declare the config protocol's constructor for the type checker alone, so the protocol keeps its guard against being instantiated. - Remove 41 unused imports, and let flake8 accept black's spacing. - Point pyright at the project's own environment, without which it resolved no dependency and reported 124 findings that were not real. - Cover the two fixes and the shared `cp`/`mv` paths with new tests.
This commit is contained in:
+22
-4
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
from unicodedata import normalize
|
||||
|
||||
from mdrsclient.api import DoiApi, FilesApi, FoldersApi, LaboratoriesApi, UsersApi
|
||||
@@ -20,11 +19,30 @@ from mdrsclient.utils import page_num_from_url
|
||||
class MdrsService:
|
||||
config_class: type[ConfigInterface] = ConfigFile
|
||||
|
||||
def __init__(self, connection: MDRSConnection, config_class: type[ConfigInterface] | None = None):
|
||||
self.connection = connection
|
||||
def __init__(self, connection: MDRSConnection | None, config_class: type[ConfigInterface] | None = None):
|
||||
self.__connection = connection
|
||||
if config_class is not None:
|
||||
self.config_class = config_class
|
||||
|
||||
@property
|
||||
def connection(self) -> MDRSConnection:
|
||||
"""
|
||||
The connection every remote operation goes through.
|
||||
|
||||
Optional to supply, because `config` and `version` do their work without a remote
|
||||
and are reached through the same client. Asking for it when none was given is a
|
||||
mistake in the caller, and says so rather than failing later on `None`.
|
||||
"""
|
||||
if self.__connection is None:
|
||||
raise MissingConfigurationException("This operation requires a remote host.")
|
||||
return self.__connection
|
||||
|
||||
@connection.setter
|
||||
def connection(self, connection: MDRSConnection | None) -> None:
|
||||
# Assignable as it always was: this is a property to check for absence on read,
|
||||
# not to make the connection fixed once the client is built.
|
||||
self.__connection = connection
|
||||
|
||||
@classmethod
|
||||
def create_connection(
|
||||
cls, remote: str, cache: CacheInterface | None = None, config: ConfigInterface | None = None
|
||||
@@ -182,7 +200,7 @@ class MdrsService:
|
||||
if folder.lock:
|
||||
if password is None:
|
||||
raise UnauthorizedException(f"Folder for DOI `{doi_clean}` is locked.")
|
||||
folder_api.auth(doi_resp.folder.id, password)
|
||||
folder_api.auth(doi_resp.folder_id, password)
|
||||
|
||||
lab_api = LaboratoriesApi(self.connection)
|
||||
labs = lab_api.list()
|
||||
|
||||
Reference in New Issue
Block a user