pg.allow_writable_accessors#
Accessible via pg.allow_writable_accessors
, pg.symbolic.allow_writable_accessors
.
- allow_writable_accessors(writable=True)[source]#
Returns a context manager that makes accessor writable in scope.
This function is thread-safe and can be nested. In the nested use case, the writable flag of immediate parent context is effective.
Example:
sd1 = pg.Dict() sd2 = pg.Dict(accessor_writable=False) with pg.allow_writable_accessors(False): sd1.a = 2 # NOT OK sd2.a = 2 # NOT OK with pg.allow_writable_accessors(True): sd1.a = 2 # OK sd2.a = 2 # OK with pg.allow_writable_accessors(None): sd1.a = 1 # OK sd2.a = 1 # NOT OK
- Return type:
- Parameters:
writable – If True, allow write access with accessors (__setattr__, __setitem__) for all symbolic values in scope. If False, disallow write access via accessors for all symbolic values in scope, even if individual objects allow so. If None, honor object-level accessor_writable flag.
- Returns:
- A context manager that allows/disallows writable accessors of all
symbolic values in scope. After leaving the scope, the accessor_writable flag of individual objects will remain intact.