Previous topic

stalker.ext.validatedList

Next topic

stalker.utils.path_to_exec

This Page

stalker.ext.validatedList.ValidatedList

Inheritance diagram of stalker.ext.validatedList.ValidatedList

class stalker.ext.validatedList.ValidatedList(list_=[], element_type=None, validator=None)[source]

Bases: list

A list variant which accepts only one type of element.

A ValidatedList is a regular Python list with overriden methods which helps validating the elements in regular list actions. Uses the type of the first assigned element if no type_ is defined.

Reduces the given list_ to elements with the same type of the first element if the type_ argument is None or uses the type_ argument if given.

Parameters:
  • list_ – The list to initialize this ValidatedList instance, simply all the data will be copied to the current ValidatedList instance. Also sets the type that this ValidatedList instance works on if no type_ argument is given and the given list will be reduced to the same type of objects defined with the first elements type or with the given type_ argument, default value is an empty list.
  • type_ – If given, the ValidatedList will accept only this type of objects. If both the list_ and the type_ arguments are given the the type_ will be used as the forced type. Can be a string showing the absolute path of the type object.
  • validator

    A callable which will be called with the newly passed elements. The ValidatedList instance will call the callable when the __setitem__, __setslice__, append, extend, insert, __add__, __iadd__, pop or remove methods are called. The regular validations will still be done by the ValidatedList instance, but for extra actions (like back reference updates for example) the callable will be called with the list of elements. Callables should be in the following form:

    def func1(list_of_elements_added, list_of_elements_removed):
        pass
    
__init__(list_=[], element_type=None, validator=None)[source]

Methods

__init__([list_, element_type, validator])
append(object) L.append(object) – append object to end
extend(iterable) L.extend(iterable) – extend list by appending elements from the iterable
insert(index, object) L.insert(index, object) – insert object before index
pop([index]) L.pop([index]) -> item – remove and return item at index (default last).
remove(value) L.remove(value) – remove first occurrence of value.

Attributes

count L.count(value) -> integer – return number of occurrences of value
index L.index(value, [start, [stop]]) -> integer – return first index of value.
reverse L.reverse() – reverse IN PLACE
sort L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE;
append(object)[source]

L.append(object) – append object to end

This is the overriden version of the original method.

extend(iterable)[source]

L.extend(iterable) – extend list by appending elements from the iterable

This is the overriden version of the original method.

insert(index, object)[source]

L.insert(index, object) – insert object before index

This is the overriden version of the original method.

pop(index=-1)[source]

L.pop([index]) -> item – remove and return item at index (default last). Raises IndexError if list is empty or index is out of range.

This is the overriden version of the original method.

remove(value)[source]

L.remove(value) – remove first occurrence of value. Raises ValueError if the value is not present.

count

L.count(value) -> integer – return number of occurrences of value

index

L.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.

reverse

L.reverse() – reverse IN PLACE

sort

L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE; cmp(x, y) -> -1, 0, 1