bridge.utils.instantiate_utils#

Module Contents#

Functions#

_as_module_prefix

Ensure prefix ends with ‘.’ so allowlist matches at module boundaries.

_seed_allowlist

register_allowed_target_prefix

Register an additional allowed module prefix for target instantiation.

_reject_unsafe_target_name

Reject known unsafe target names without importing their modules.

_validate_target_prefix

Validate that a target string is permitted by Bridge hardening rules.

_resolve_target

Resolve target string, type, or callable after Bridge validation.

Data#

API#

bridge.utils.instantiate_utils._ALLOWED_TARGET_PREFIXES: set[str]#

None

bridge.utils.instantiate_utils._TARGET_ALLOWLIST_MUTATORS: tuple[str, ...]#

(‘add_prefix’, ‘remove_prefix’, ‘add_exact’, ‘remove_exact’, ‘disable’, ‘enable’)

bridge.utils.instantiate_utils._ALLOWED_PRIVATE_TARGETS: set[str]#

None

bridge.utils.instantiate_utils._DISALLOWED_TARGETS: set[str]#

None

bridge.utils.instantiate_utils._DISALLOWED_CANONICAL_TARGETS: set[str]#

None

bridge.utils.instantiate_utils._DISALLOWED_TRANSFORMERS_PREFIXES: tuple[str, ...]#

(‘transformers.dynamic_module_utils.’, ‘transformers.utils.import_utils.’, ‘transformers.pipelines.’…

bridge.utils.instantiate_utils._DISALLOWED_TRANSFORMERS_METHODS: frozenset[str]#

‘frozenset(…)’

bridge.utils.instantiate_utils._DISALLOWED_CALLABLE_FIELD_NAMES: set[str]#

None

bridge.utils.instantiate_utils._as_module_prefix(prefix: str) → str#

Ensure prefix ends with ‘.’ so allowlist matches at module boundaries.

bridge.utils.instantiate_utils._seed_allowlist() → None#
bridge.utils.instantiate_utils.register_allowed_target_prefix(prefix: str) → None#

Register an additional allowed module prefix for target instantiation.

This allows extending the default allowlist for use cases that require instantiating classes from other packages.

bridge.utils.instantiate_utils._reject_unsafe_target_name(
*,
target: str,
full_key: str | int,
) → None#

Reject known unsafe target names without importing their modules.

bridge.utils.instantiate_utils._validate_target_prefix(*, target: str, full_key: str | int) → None#

Validate that a target string is permitted by Bridge hardening rules.

bridge.utils.instantiate_utils._resolve_target(
target: str | type | Callable[..., Any],
full_key: str | int,
check_callable: bool = True,
) → type | Callable[..., Any] | object#

Resolve target string, type, or callable after Bridge validation.