pg.contains

Accessible via pg.contains, pg.symbolic.contains.

contains(x, value=None, type=None)[source]

Returns if a value contains values of specific type.

Example:

@pg.members([
    ('x', pg.typing.Any()),
    ('y', pg.typing.Any())
])
class A(pg.Object):
  pass

# Test if a symbolic tree contains a value.
assert pg.contains(A('a', 'b'), 'a')
assert not pg.contains(A('a', 'b'), A)

# Test if a symbolic tree contains a type.
assert pg.contains({'x': A(1, 2)}, type=A)
assert pg.contains({'x': A(1, 2)}, type=int)
assert pg.contains({'x': A(1, 2)}, type=(int, float))
Return type:

bool

Parameters:
  • x – The source value to query against.

  • value – Value of sub-node to contain. Applicable when type is None.

  • type – A type or a tuple of types for the sub-nodes. Applicable if not None.

Returns:

True if x itself or any of its sub-nodes equal to value or is an instance of value_type.