fixed type errors when pylance type checking mode is strict.

This commit is contained in:
2023-07-19 21:47:47 +09:00
parent 23025bd679
commit 08d8a0626a
24 changed files with 387 additions and 236 deletions

View File

@ -1,5 +1,6 @@
import os
from argparse import Namespace, _SubParsersAction
from argparse import Namespace
from typing import Any
from unicodedata import normalize
from mdrsclient.api import FolderApi
@ -9,20 +10,25 @@ from mdrsclient.exceptions import IllegalArgumentException
class MkdirCommand(BaseCommand):
@classmethod
def register(cls, parsers: _SubParsersAction) -> None:
command = cls()
def register(cls, parsers: Any) -> None:
mkdir_parser = parsers.add_parser("mkdir", help="create a new folder")
mkdir_parser.add_argument("remote_path", help="remote folder path (remote:/lab/path/)")
mkdir_parser.set_defaults(func=command.mkdir)
mkdir_parser.set_defaults(func=cls.func)
def mkdir(self, args: Namespace) -> None:
(remote, laboratory_name, r_path) = self._parse_remote_host_with_path(args.remote_path)
@classmethod
def func(cls, args: Namespace) -> None:
remote_path = str(args.remote_path)
cls.mkdir(remote_path)
@classmethod
def mkdir(cls, remote_path: str) -> None:
(remote, laboratory_name, r_path) = cls._parse_remote_host_with_path(remote_path)
r_path = r_path.rstrip("/")
r_dirname = os.path.dirname(r_path)
r_basename = os.path.basename(r_path)
connection = self._create_connection(remote)
laboratory = self._find_laboratory(connection, laboratory_name)
parent_folder = self._find_folder(connection, laboratory, r_dirname)
connection = cls._create_connection(remote)
laboratory = cls._find_laboratory(connection, laboratory_name)
parent_folder = cls._find_folder(connection, laboratory, r_dirname)
if parent_folder.find_sub_folder(r_basename) is not None or parent_folder.find_file(r_basename) is not None:
raise IllegalArgumentException(f"Cannot create folder `{r_path}`: File exists.")
folder_api = FolderApi(connection)