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), the private instance only knows about new assignments. This means you really should not re-assign variables in a with 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
>>>
__init__(ns: dict[str, Any] | None = None, /) None#

Methods

__init__([ns])

Attributes

all

The attached __all__.

ns

The attached namespace.

property all: list[str]#

The attached __all__.

property ns: dict[str, _X]#

The attached namespace.