pg.allow_partial¶
Accessible via pg.allow_partial
, pg.symbolic.allow_partial
.
- allow_partial(allow=True)[source]¶
Returns a context manager that allows partial values in scope.
This function is thread-safe and can be nested. In the nested use case, the allow flag of immediate parent context is effective.
Example:
@pg.members([ ('x', pg.typing.Int()), ('y', pg.typing.Int()) ]) class A(pg.Object): pass with pg.allow_partial(True): a = A(x=1) # Missing `y`, but OK with pg.allow_partial(False): a.rebind(x=pg.MISSING_VALUE) # NOT OK a.rebind(x=pg.MISSING_VALUE) # OK
- Return type:
- Parameters:
allow – If True, allow partial symbolic values in scope. If False, do not allow partial symbolic values in scope even if individual objects allow so. If None, honor object-level allow_partial property.
- Returns:
- A context manager that allows/disallow partial symbolic values in scope.
After leaving the scope, the allow_partial state of individual objects will remain intact.