rberga06.utils.access.private#
- class rberga06.utils.access.private(ns: dict[str, Any] | None = None, /)#
Bases:
_access_specialized
[_X
]Mark something private.
- Parameters:
ns – The namespace in which to operate. Defaults to the caller’s locals().
- Example:
>>> locals().clear() >>> from rberga06.utils.access import * >>> @private() ... def foo(x: int) -> int: ... return x ... >>> with private(): ... _x: str = "private" ... y: str = "also private" ... >>> __all__ [] >>> __all__ is private().all True
Important
When using the context manager syntax (aka
with private():
blocks), theprivate
instance only knows about new assignments. This means you really should not re-assign variables in awith private():
block. For example:>>> # This is ok >>> with private(): ... x: int = 0 ... >>> x = 42 >>> >>> # This is not >>> x: int = 0 >>> with private(): ... x: int = 42 >>>
Methods
__init__
([ns])Attributes