Skip to content

MigrationParameterDefinition

A class to define a migration parameter.

Source code in pum/migration_parameter.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class MigrationParameterDefinition:
    """
    A class to define a migration parameter.
    """

    def __init__(
        self,
        name: str,
        type_: str | MigrationParameterType,
        default: str | int | float = None,
        description: str = None,
    ):
        """
        Initialize a MigrationParameterDefintion instance.

        Args:
            name (str): The name of the parameter.
            type_ (str | MigrationParameterType): The type of the parameter, as a string or MigrationParameterType.
            default (str | int | float, optional): The default value for the parameter. Defaults to None.
            description (str, optional): A description of the parameter. Defaults to None.

        Raises:
            ValueError: If type_ is a string and not a valid MigrationParameterType.
            TypeError: If type_ is not a string or ParameterType.
        """
        self.name = name
        if isinstance(type_, MigrationParameterType):
            self.type = type_
        elif isinstance(type_, str):
            try:
                self.type = MigrationParameterType(type_)
            except ValueError:
                raise ValueError(f"Invalid parameter type: {type_}")
        else:
            raise TypeError("type_ must be a str or MigrationParameterType")
        self.default = default
        self.description = description

    def __repr__(self):
        return f"MigrationParameter(name={self.name}, type={self.type}, default={self.default}, description={self.description})"

    def __eq__(self, other):
        if not isinstance(other, MigrationParameterDefinition):
            return NotImplemented
        return (
            self.name == other.name
            and self.type == other.type
            and self.default == other.default
            and self.description == other.description
        )

__init__

__init__(name: str, type_: str | MigrationParameterType, default: str | int | float = None, description: str = None)

Initialize a MigrationParameterDefintion instance.

Parameters:

Name Type Description Default
name str

The name of the parameter.

required
type_ str | MigrationParameterType

The type of the parameter, as a string or MigrationParameterType.

required
default str | int | float

The default value for the parameter. Defaults to None.

None
description str

A description of the parameter. Defaults to None.

None

Raises:

Type Description
ValueError

If type_ is a string and not a valid MigrationParameterType.

TypeError

If type_ is not a string or ParameterType.

Source code in pum/migration_parameter.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(
    self,
    name: str,
    type_: str | MigrationParameterType,
    default: str | int | float = None,
    description: str = None,
):
    """
    Initialize a MigrationParameterDefintion instance.

    Args:
        name (str): The name of the parameter.
        type_ (str | MigrationParameterType): The type of the parameter, as a string or MigrationParameterType.
        default (str | int | float, optional): The default value for the parameter. Defaults to None.
        description (str, optional): A description of the parameter. Defaults to None.

    Raises:
        ValueError: If type_ is a string and not a valid MigrationParameterType.
        TypeError: If type_ is not a string or ParameterType.
    """
    self.name = name
    if isinstance(type_, MigrationParameterType):
        self.type = type_
    elif isinstance(type_, str):
        try:
            self.type = MigrationParameterType(type_)
        except ValueError:
            raise ValueError(f"Invalid parameter type: {type_}")
    else:
        raise TypeError("type_ must be a str or MigrationParameterType")
    self.default = default
    self.description = description