duit.arguments.adapters.BaseTypeAdapter
1import argparse 2from abc import ABC, abstractmethod 3from typing import Any 4 5from duit.arguments.Argument import Argument 6 7 8class BaseTypeAdapter(ABC): 9 """ 10 An abstract base class for defining type adapters for command-line arguments. 11 12 Attributes: 13 None 14 """ 15 16 @abstractmethod 17 def handles_type(self, obj: Any) -> bool: 18 """ 19 Check if the type adapter can handle a specific data type. 20 21 Args: 22 obj (Any): The data type to be checked. 23 24 Returns: 25 bool: True if the type adapter can handle the data type, False otherwise. 26 """ 27 pass 28 29 @abstractmethod 30 def add_argument(self, parser, argument: Argument, obj: Any): 31 """ 32 Add a command-line argument to an argparse parser based on the type adapter. 33 34 Args: 35 parser (argparse.ArgumentParser): The argparse parser to which the argument will be added. 36 argument (Argument): The Argument annotation associated with the argument. 37 obj (Any): The value of the argument. 38 39 Returns: 40 None 41 """ 42 pass 43 44 @abstractmethod 45 def parse_argument(self, args: argparse.Namespace, ns_dest: str, argument: Argument, obj: Any) -> Any: 46 """ 47 Parse a command-line argument value from argparse namespace and return it based on the type adapter. 48 49 Args: 50 args (argparse.Namespace): The argparse namespace containing the parsed command-line arguments. 51 ns_dest (str): The namespace attribute name of the argument. 52 argument (Argument): The Argument annotation associated with the argument. 53 obj (Any): The original value of the argument. 54 55 Returns: 56 Any: The parsed value of the argument. 57 """ 58 pass
9class BaseTypeAdapter(ABC): 10 """ 11 An abstract base class for defining type adapters for command-line arguments. 12 13 Attributes: 14 None 15 """ 16 17 @abstractmethod 18 def handles_type(self, obj: Any) -> bool: 19 """ 20 Check if the type adapter can handle a specific data type. 21 22 Args: 23 obj (Any): The data type to be checked. 24 25 Returns: 26 bool: True if the type adapter can handle the data type, False otherwise. 27 """ 28 pass 29 30 @abstractmethod 31 def add_argument(self, parser, argument: Argument, obj: Any): 32 """ 33 Add a command-line argument to an argparse parser based on the type adapter. 34 35 Args: 36 parser (argparse.ArgumentParser): The argparse parser to which the argument will be added. 37 argument (Argument): The Argument annotation associated with the argument. 38 obj (Any): The value of the argument. 39 40 Returns: 41 None 42 """ 43 pass 44 45 @abstractmethod 46 def parse_argument(self, args: argparse.Namespace, ns_dest: str, argument: Argument, obj: Any) -> Any: 47 """ 48 Parse a command-line argument value from argparse namespace and return it based on the type adapter. 49 50 Args: 51 args (argparse.Namespace): The argparse namespace containing the parsed command-line arguments. 52 ns_dest (str): The namespace attribute name of the argument. 53 argument (Argument): The Argument annotation associated with the argument. 54 obj (Any): The original value of the argument. 55 56 Returns: 57 Any: The parsed value of the argument. 58 """ 59 pass
An abstract base class for defining type adapters for command-line arguments.
Attributes: None
17 @abstractmethod 18 def handles_type(self, obj: Any) -> bool: 19 """ 20 Check if the type adapter can handle a specific data type. 21 22 Args: 23 obj (Any): The data type to be checked. 24 25 Returns: 26 bool: True if the type adapter can handle the data type, False otherwise. 27 """ 28 pass
Check if the type adapter can handle a specific data type.
Args: obj (Any): The data type to be checked.
Returns: bool: True if the type adapter can handle the data type, False otherwise.
30 @abstractmethod 31 def add_argument(self, parser, argument: Argument, obj: Any): 32 """ 33 Add a command-line argument to an argparse parser based on the type adapter. 34 35 Args: 36 parser (argparse.ArgumentParser): The argparse parser to which the argument will be added. 37 argument (Argument): The Argument annotation associated with the argument. 38 obj (Any): The value of the argument. 39 40 Returns: 41 None 42 """ 43 pass
Add a command-line argument to an argparse parser based on the type adapter.
Args: parser (argparse.ArgumentParser): The argparse parser to which the argument will be added. argument (Argument): The Argument annotation associated with the argument. obj (Any): The value of the argument.
Returns: None
45 @abstractmethod 46 def parse_argument(self, args: argparse.Namespace, ns_dest: str, argument: Argument, obj: Any) -> Any: 47 """ 48 Parse a command-line argument value from argparse namespace and return it based on the type adapter. 49 50 Args: 51 args (argparse.Namespace): The argparse namespace containing the parsed command-line arguments. 52 ns_dest (str): The namespace attribute name of the argument. 53 argument (Argument): The Argument annotation associated with the argument. 54 obj (Any): The original value of the argument. 55 56 Returns: 57 Any: The parsed value of the argument. 58 """ 59 pass
Parse a command-line argument value from argparse namespace and return it based on the type adapter.
Args: args (argparse.Namespace): The argparse namespace containing the parsed command-line arguments. ns_dest (str): The namespace attribute name of the argument. argument (Argument): The Argument annotation associated with the argument. obj (Any): The original value of the argument.
Returns: Any: The parsed value of the argument.