pg.symbolic.ValueFromParentChain¶
Accessible via pg.symbolic.ValueFromParentChain
.
- class ValueFromParentChain[source]¶
Bases:
pg.InferredValue
A value that could inferred from the parent chain.
For example:
class A(pg.Object): x: int y: int = pg.symbolic.ValueFromParentChain() # Not okay: `x` is not inferential and is not specified. A() # Okay: both `x` and `y` are specified. A(x=1, y=2) # Okay: `y` is inferential, hence optional. a = A(x=1) # Raises: `y` is neither specified during __init__ # nor provided from the context. a.y d = pg.Dict(y=2, z=pg.Dict(a=a)) # `a.y` now refers to `d.a` since `d` is in its symbolic parent chain, # aka. context. assert a.y == 2
Methods:
infer
(**kwargs)Returns the inferred value.
Attributes:
Returns the key for attribute inference from parents.
- infer(**kwargs)[source]¶
Returns the inferred value.
- Return type:
- Parameters:
**kwargs – Optional keyword arguments for inference, which are usually inferential subclass specific.
- Returns:
Inferred value.
- Raises:
AttributeError – If the value cannot be inferred.