rberga06.utils.access.access#
- class rberga06.utils.access.access(ns: dict[str, Any] | None = None, /)#
Bases:
_access
[_X
]Access specifiers.
- Parameters:
ns – The namespace in which to operate. Defaults to the caller’s
locals()
.- Example:
>>> locals().clear() >>> from rberga06.utils.access import * >>> __all__ Traceback (most recent call last): ... NameError: name '__all__' is not defined >>> a = access() >>> @a.public ... def _foo(x: int) -> int: ... return x ... >>> @a.private ... def priv(y: str) -> str: ... return y ... >>> with a.public: ... _x: str = "public" ... >>> with a.private: ... y: int = 42 ... >>> __all__ # it's now magically defined ['_foo', '_x'] >>> __all__ is a.all True
Important
When using the context manager syntax (for example,
with a.public:
blocks), theaccess
instance only knows about new assignments. This means you really should not re-assign variables in awith a.public:
orwith a.private:
block. For example:>>> # This is ok >>> with a.public: ... x: int = 0 ... >>> x = 42 >>> >>> # This is not >>> x: int = 0 >>> with a.public: ... x: int = 42 >>>
Methods
__init__
([ns])Attributes
The attached
__all__
.The attached namespace.
Mark something private
Mark something public