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