pyfcstm.utils.safe

Utility module for creating safe sequence identifiers.

This module provides functionality to convert sequences of strings into safe, underscore-separated identifiers. It’s particularly useful for generating consistent naming conventions from potentially inconsistent input strings.

The main use case is to take a collection of string segments that may use different naming conventions (CamelCase, snake_case, kebab-case, etc.) and normalize them into a consistent, safe identifier format using underscores as separators.

sequence_safe

pyfcstm.utils.safe.sequence_safe(segments: Iterable[str]) str[source]

Convert a sequence of strings into a safe underscore-separated identifier.

This function takes a sequence of strings, converts each to underscore format, normalizes multiple consecutive underscores to single underscores, and joins them with double underscores (‘__’). This is useful for creating consistent identifiers from potentially inconsistent input strings.

Parameters:

segments (Iterable[str]) – A sequence of strings to be converted into a safe identifier.

Returns:

A safe underscore-separated identifier string.

Return type:

str

Example::
>>> sequence_safe(['CamelCase', 'snake_case', 'kebab-case'])
'camel_case__snake_case__kebab_case'
>>> sequence_safe(['Hello World', 'Test___String'])
'hello_world__test_string'