Skip to content

Reference

privates.__about__

__author__ = 'ZeroIntensity' module-attribute

__authors__ = (__author__) module-attribute

__license__ = 'MIT' module-attribute

__version__ = '0.2.0' module-attribute

privates.exceptions

__all__ = ('PrivatesError', 'AccessError', 'FrameError') module-attribute

AccessError

Bases: PrivatesError

Caller does not have access to the target.

FrameError

Bases: PrivatesError

Failed to get the frame.

PrivatesError

Bases: Exception

Base exception for all privates.py errors.

privates.modifiers

A = TypeVar('A', bound=Union[type, Callable]) module-attribute

P = ParamSpec('P') module-attribute

T = TypeVar('T') module-attribute

__all__ = ('supports_private', 'class_modifier', 'function_modifier', 'private', 'friend') module-attribute

class_modifier(target: type[T]) -> type[T]

Modify the access rules for a class.

Example
from privates import access_modifier

@class_modifier()
class Hello:
    ...

# Hello is now only usable in this module!

friend(tp: type[Any]) -> Callable[[A], A]

Allow the type or function to touch private attributes of the type.

function_modifier(func: Callable[P, T]) -> Callable[P, T]

Apply a private modifier to a function.

private(func_or_type: A) -> A

Apply class_modifier if the object is a class, otherwise apply function_modifier.

supports_private(tp: type[T]) -> type[T]

Enable checking of attributes on the target type.

Parameters:

Name Type Description Default
tp type[T]

Type to enable checking on.

required

privates._util

__all__ = ('get_back_frame') module-attribute

get_back_frame() -> Frame

Get the last frame outside of privates.py