mirror of
https://github.com/clearml/clearml-agent
synced 2025-01-31 17:16:51 +00:00
22 lines
552 B
Python
22 lines
552 B
Python
|
|
|
|
class ModelCollection(list):
|
|
|
|
"""`ModelCollection` is list which validates stored values.
|
|
|
|
Validation is made with use of field passed to `__init__` at each point,
|
|
when new value is assigned.
|
|
|
|
"""
|
|
|
|
def __init__(self, field):
|
|
self.field = field
|
|
|
|
def append(self, value):
|
|
self.field.validate_single_value(value)
|
|
super(ModelCollection, self).append(value)
|
|
|
|
def __setitem__(self, key, value):
|
|
self.field.validate_single_value(value)
|
|
super(ModelCollection, self).__setitem__(key, value)
|