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), the public instance only knows about new assignments. This means you really should not re-assign variables in a with 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
>>>
__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.