util.validatedList module

ValidatedList: a list that checks every item put in it against a predicate, and that’s Dirtyable (see util.dirtyable).

Created on Jul 13, 2026

Code author: Rob Kremer <robkremer@me.com>

class util.validatedList.ValidatedList(f: Callable[[T], bool], iterable: Iterable = ())

Bases: list[T], Dirtyable, Generic

A list subclass that enforces a predicate on every item inserted.

Parameters:
  • f (Callable[[T], bool]) – Predicate function; an item is rejected if f(item) is falsy.

  • iterable (Iterable[T]) – Initial items to populate the list with.

Raises:

ValueError – If any item (initial or later inserted) fails the predicate.

__init__(f: Callable[[T], bool], iterable: Iterable = ()) → None
Parameters:
  • f (Callable[[T], bool])

  • iterable (Iterable[T])

_check(i: T) → None

Validate a single item against the predicate.

Parameters:

i (T) – Item to validate.

Raises:

ValueError – If f(i) is falsy.

checking(check: bool | None = None) → bool

Enable, Disable, or find the value of running the validation function on data entry.

Parameters:

check (bool|None) – if None, merely return the checking status, otherwise set the checking status on (True) or off (False).

Returns:

True if entries are now being validated, False if not.

Return type:

bool

append(i: T) → None
Parameters:

i (T) – Item to append.

Raises:

ValueError – If f(i) is falsy.

extend(iterable: Iterable) → None
Parameters:

iterable (Iterable[T]) – Items to extend the list with.

Raises:

ValueError – If any item fails the predicate.

insert(index: SupportsIndex, i: T) → None
Parameters:
  • index (int) – Position to insert at.

  • i (T) – Item to insert.

Raises:

ValueError – If f(i) is falsy.

__setitem__(index, value) → None

Handle both single-index and slice assignment.

Parameters:
  • index – Index or slice to assign to.

  • value – Value(s) to assign.

Raises:

ValueError – If any assigned item fails the predicate.