fixed type errors when pylance type checking mode is strict.
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
import dataclasses
 | 
			
		||||
import os
 | 
			
		||||
from argparse import Namespace, _SubParsersAction
 | 
			
		||||
from argparse import Namespace
 | 
			
		||||
from typing import Any
 | 
			
		||||
from unicodedata import normalize
 | 
			
		||||
 | 
			
		||||
from pydantic import TypeAdapter
 | 
			
		||||
@@ -13,16 +14,22 @@ from mdrsclient.models import File, FolderSimple
 | 
			
		||||
 | 
			
		||||
class MvCommand(BaseCommand):
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def register(cls, parsers: _SubParsersAction) -> None:
 | 
			
		||||
        command = cls()
 | 
			
		||||
    def register(cls, parsers: Any) -> None:
 | 
			
		||||
        mv_parser = parsers.add_parser("mv", help="move or rename the file or folder")
 | 
			
		||||
        mv_parser.add_argument("src_path", help="source remote path (remote:/lab/path/src)")
 | 
			
		||||
        mv_parser.add_argument("dest_path", help="destination remote path (remote:/lab/path/dest)")
 | 
			
		||||
        mv_parser.set_defaults(func=command.mv)
 | 
			
		||||
        mv_parser.set_defaults(func=cls.func)
 | 
			
		||||
 | 
			
		||||
    def mv(self, args: Namespace) -> None:
 | 
			
		||||
        (s_remote, s_laboratory_name, s_path) = self._parse_remote_host_with_path(args.src_path)
 | 
			
		||||
        (d_remote, d_laboratory_name, d_path) = self._parse_remote_host_with_path(args.dest_path)
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def func(cls, args: Namespace) -> None:
 | 
			
		||||
        src_path = str(args.src_path)
 | 
			
		||||
        dest_path = str(args.dest_path)
 | 
			
		||||
        cls.mv(src_path, dest_path)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def mv(cls, src_path: str, dest_path: str) -> None:
 | 
			
		||||
        (s_remote, s_laboratory_name, s_path) = cls._parse_remote_host_with_path(src_path)
 | 
			
		||||
        (d_remote, d_laboratory_name, d_path) = cls._parse_remote_host_with_path(dest_path)
 | 
			
		||||
        if s_remote != d_remote:
 | 
			
		||||
            raise IllegalArgumentException("Remote host mismatched.")
 | 
			
		||||
        if s_laboratory_name != d_laboratory_name:
 | 
			
		||||
@@ -36,10 +43,10 @@ class MvCommand(BaseCommand):
 | 
			
		||||
        else:
 | 
			
		||||
            d_dirname = os.path.dirname(d_path)
 | 
			
		||||
            d_basename = os.path.basename(d_path)
 | 
			
		||||
        connection = self._create_connection(s_remote)
 | 
			
		||||
        laboratory = self._find_laboratory(connection, s_laboratory_name)
 | 
			
		||||
        s_parent_folder = self._find_folder(connection, laboratory, s_dirname)
 | 
			
		||||
        d_parent_folder = self._find_folder(connection, laboratory, d_dirname)
 | 
			
		||||
        connection = cls._create_connection(s_remote)
 | 
			
		||||
        laboratory = cls._find_laboratory(connection, s_laboratory_name)
 | 
			
		||||
        s_parent_folder = cls._find_folder(connection, laboratory, s_dirname)
 | 
			
		||||
        d_parent_folder = cls._find_folder(connection, laboratory, d_dirname)
 | 
			
		||||
        s_file = s_parent_folder.find_file(s_basename)
 | 
			
		||||
        if s_file is not None:
 | 
			
		||||
            # source is file
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user