Skip to content

Product ID List

This part of the project documentation focuses on an information-oriented approach. Use it as a reference for the technical implementation of the pact_methodology project code.

ProductIdList

A list of ProductId objects.

Attributes:

Name Type Description
product_ids list

A list of ProductId objects.

Raises:

Type Description
ValueError

If product_ids is not a list of ProductId objects.

ValueError

If there are duplicate ProductId objects in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class ProductIdList:
    """
    A list of ProductId objects.

    Attributes:
        product_ids (list): A list of ProductId objects.

    Raises:
        ValueError: If product_ids is not a list of ProductId objects.
        ValueError: If there are duplicate ProductId objects in the list.
    """

    def __init__(self, product_ids):
        """
        Initializes a ProductIdList object.

        Args:
            product_ids (list): A list of ProductId objects.

        Raises:
            ValueError: If product_ids is not a list of ProductId objects.
            ValueError: If there are duplicate ProductId objects in the list.
        """
        if not isinstance(product_ids, list) or not all(
            isinstance(product_id, ProductId) for product_id in product_ids
        ):
            raise ValueError("product_ids must be a list of ProductId")
        if len(set(product_ids)) != len(product_ids):
            raise DuplicateIdError("Duplicate product_ids are not allowed")
        self.product_ids = product_ids

    def __iter__(self):
        """
        Returns an iterator over the ProductId objects in the list.

        Returns:
            iterator: An iterator over the ProductId objects in the list.
        """
        return iter(self.product_ids)

    def __len__(self):
        """
        Returns the number of ProductId objects in the list.

        Returns:
            int: The number of ProductId objects in the list.
        """
        return len(self.product_ids)

    def __getitem__(self, index):
        """
        Returns the ProductId object at the specified index.

        Args:
            index (int): The index of the ProductId object to return.

        Returns:
            ProductId: The ProductId object at the specified index.
        """
        return self.product_ids[index]

    def __setitem__(self, index, value):
        """
        Sets the ProductId object at the specified index.

        Args:
            index (int): The index of the ProductId object to set.
            value (ProductId): The ProductId object to set.

        Raises:
            ValueError: If value is not a ProductId object.
        """
        if not isinstance(value, ProductId):
            raise ValueError("product_id must be an instance of ProductId")
        self.product_ids[index] = value

    def __delitem__(self, index):
        """
        Deletes the ProductId object at the specified index.

        Args:
            index (int): The index of the ProductId object to delete.
        """
        del self.product_ids[index]

    def append(self, product_id):
        """
        Appends a ProductId object to the list.

        Args:
            product_id (ProductId): The ProductId object to append.

        Raises:
            ValueError: If product_id is not a ProductId object.
            ValueError: If product_id is already in the list.
        """
        if not isinstance(product_id, ProductId):
            raise ValueError("product_id must be an instance of ProductId")
        if product_id in self.product_ids:
            raise DuplicateIdError("Duplicate product_ids are not allowed")
        self.product_ids.append(product_id)

    def insert(self, index, product_id):
        """
        Inserts a ProductId object at the specified index.

        Args:
            index (int): The index at which to insert the ProductId object.
            product_id (ProductId): The ProductId object to insert.

        Raises:
            ValueError: If product_id is not a ProductId object.
            ValueError: If product_id is already in the list.
        """
        if not isinstance(product_id, ProductId):
            raise ValueError("product_id must be an instance of ProductId")
        if product_id in self.product_ids:
            raise DuplicateIdError("Duplicate product_ids are not allowed")
        self.product_ids.insert(index, product_id)

    def remove(self, product_id):
        """
        Removes a ProductId object from the list.

        Args:
            product_id (ProductId): The ProductId object to remove.

        Raises:
            ValueError: If product_id is not in the list.
        """
        if product_id not in self.product_ids:
            raise ValueError("product_id is not in the list")
        self.product_ids.remove(product_id)

__delitem__(index)

Deletes the ProductId object at the specified index.

Parameters:

Name Type Description Default
index int

The index of the ProductId object to delete.

required
Source code in pact_methodology/product_footprint/product_id_list.py
81
82
83
84
85
86
87
88
def __delitem__(self, index):
    """
    Deletes the ProductId object at the specified index.

    Args:
        index (int): The index of the ProductId object to delete.
    """
    del self.product_ids[index]

__getitem__(index)

Returns the ProductId object at the specified index.

Parameters:

Name Type Description Default
index int

The index of the ProductId object to return.

required

Returns:

Name Type Description
ProductId

The ProductId object at the specified index.

Source code in pact_methodology/product_footprint/product_id_list.py
54
55
56
57
58
59
60
61
62
63
64
def __getitem__(self, index):
    """
    Returns the ProductId object at the specified index.

    Args:
        index (int): The index of the ProductId object to return.

    Returns:
        ProductId: The ProductId object at the specified index.
    """
    return self.product_ids[index]

__init__(product_ids)

Initializes a ProductIdList object.

Parameters:

Name Type Description Default
product_ids list

A list of ProductId objects.

required

Raises:

Type Description
ValueError

If product_ids is not a list of ProductId objects.

ValueError

If there are duplicate ProductId objects in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(self, product_ids):
    """
    Initializes a ProductIdList object.

    Args:
        product_ids (list): A list of ProductId objects.

    Raises:
        ValueError: If product_ids is not a list of ProductId objects.
        ValueError: If there are duplicate ProductId objects in the list.
    """
    if not isinstance(product_ids, list) or not all(
        isinstance(product_id, ProductId) for product_id in product_ids
    ):
        raise ValueError("product_ids must be a list of ProductId")
    if len(set(product_ids)) != len(product_ids):
        raise DuplicateIdError("Duplicate product_ids are not allowed")
    self.product_ids = product_ids

__iter__()

Returns an iterator over the ProductId objects in the list.

Returns:

Name Type Description
iterator

An iterator over the ProductId objects in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
36
37
38
39
40
41
42
43
def __iter__(self):
    """
    Returns an iterator over the ProductId objects in the list.

    Returns:
        iterator: An iterator over the ProductId objects in the list.
    """
    return iter(self.product_ids)

__len__()

Returns the number of ProductId objects in the list.

Returns:

Name Type Description
int

The number of ProductId objects in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
45
46
47
48
49
50
51
52
def __len__(self):
    """
    Returns the number of ProductId objects in the list.

    Returns:
        int: The number of ProductId objects in the list.
    """
    return len(self.product_ids)

__setitem__(index, value)

Sets the ProductId object at the specified index.

Parameters:

Name Type Description Default
index int

The index of the ProductId object to set.

required
value ProductId

The ProductId object to set.

required

Raises:

Type Description
ValueError

If value is not a ProductId object.

Source code in pact_methodology/product_footprint/product_id_list.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __setitem__(self, index, value):
    """
    Sets the ProductId object at the specified index.

    Args:
        index (int): The index of the ProductId object to set.
        value (ProductId): The ProductId object to set.

    Raises:
        ValueError: If value is not a ProductId object.
    """
    if not isinstance(value, ProductId):
        raise ValueError("product_id must be an instance of ProductId")
    self.product_ids[index] = value

append(product_id)

Appends a ProductId object to the list.

Parameters:

Name Type Description Default
product_id ProductId

The ProductId object to append.

required

Raises:

Type Description
ValueError

If product_id is not a ProductId object.

ValueError

If product_id is already in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def append(self, product_id):
    """
    Appends a ProductId object to the list.

    Args:
        product_id (ProductId): The ProductId object to append.

    Raises:
        ValueError: If product_id is not a ProductId object.
        ValueError: If product_id is already in the list.
    """
    if not isinstance(product_id, ProductId):
        raise ValueError("product_id must be an instance of ProductId")
    if product_id in self.product_ids:
        raise DuplicateIdError("Duplicate product_ids are not allowed")
    self.product_ids.append(product_id)

insert(index, product_id)

Inserts a ProductId object at the specified index.

Parameters:

Name Type Description Default
index int

The index at which to insert the ProductId object.

required
product_id ProductId

The ProductId object to insert.

required

Raises:

Type Description
ValueError

If product_id is not a ProductId object.

ValueError

If product_id is already in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def insert(self, index, product_id):
    """
    Inserts a ProductId object at the specified index.

    Args:
        index (int): The index at which to insert the ProductId object.
        product_id (ProductId): The ProductId object to insert.

    Raises:
        ValueError: If product_id is not a ProductId object.
        ValueError: If product_id is already in the list.
    """
    if not isinstance(product_id, ProductId):
        raise ValueError("product_id must be an instance of ProductId")
    if product_id in self.product_ids:
        raise DuplicateIdError("Duplicate product_ids are not allowed")
    self.product_ids.insert(index, product_id)

remove(product_id)

Removes a ProductId object from the list.

Parameters:

Name Type Description Default
product_id ProductId

The ProductId object to remove.

required

Raises:

Type Description
ValueError

If product_id is not in the list.

Source code in pact_methodology/product_footprint/product_id_list.py
125
126
127
128
129
130
131
132
133
134
135
136
137
def remove(self, product_id):
    """
    Removes a ProductId object from the list.

    Args:
        product_id (ProductId): The ProductId object to remove.

    Raises:
        ValueError: If product_id is not in the list.
    """
    if product_id not in self.product_ids:
        raise ValueError("product_id is not in the list")
    self.product_ids.remove(product_id)