easytree.undefined#

class easytree.undefined(parent, key)#

Undefined node

The undefined node can be dynamically cast as a dict or list node depending on mutations called on it (e.g. setting an item, setting at attribute, sorting)

Parameters:
  • key (hashable) – the key of the undefined value in its parent

  • parent (list, dict) – the containing parent

Example

>>> import easytree

>>> person = easytree.dict()
>>> person.address
<undefined 'address'>

>>> person.address.country
<undefined 'country'>

>>> person.address.country = "United States"
>>> person.address.country
"United States"

>>> person
{"address": {"country": "United States"}}
append(*args, **kwargs)#

Cast as list and append value

count(value)#

Return number of occurrences of value (read-only).

extend(other)#

Cast as list and extend with other

get(key, default=None)#

Return default value (read-only)

Parameters:
  • key (hashable) – the key to look-up

  • default (any) – the default value if the key does not exist

index(value, start=0, stop=9223372036854775807)#

Return first index of value (read-only)

insert(index, value)#

Cast as list and insert value at index

Parameters:
  • index (int) – the index

  • value (any) – the value

items()#

Return items of empty the dict (read-only)

keys()#

Return keys of empty the dict (read-only)

pop(*args)#
If the node has been cast as a dict:

remove and return the item under the given key (first argument), otherwse the default

If the node has been cast as a list:

remove and return the item at the given position in the list

Otherwise, raise a KeyError

popitem()#

Cast as dict and remove and return the last item (key, value pair) inserted into the dictionary

Raises:
  • KeyError – if the dict is empty

  • AttributeError – if the dict is frozen if the dict is sealed

remove(x)#

Cast as list and remove the first item from the list whose value is equal to x.

Parameters:

x (any) – the value to remove

Return type:

None

Raises:
  • TypeError – if the list is sealed or frozen

  • ValueError – if there is no such item

reverse()#

Cast as list and reverse the elements in place.

Return type:

None

Raises:

TypeError – if the list is sealed or frozen

setdefault(key, default)#

Cast as dict and insert default value at key

Parameters:
  • key (hashable) – the key to look-up

  • default (any) – the default value if the key does not exist

sort(*, key=None, reverse=False)#

Cast as list and sort the items in place

Return type:

None

Raises:

TypeError – if the list is frozen

update(other)#

Cast as dict and insert items from other

Parameters:

other (mapping) – other dictionary

values()#

Return values of empty the dict (read-only)