is_safe_macro_name#

scikitplot.cython.is_safe_macro_name(name, *, allow_reserved=False)[source]#

Return True when a C preprocessor macro name is safe to define.

Parameters:
namestr

Macro name (the left-hand side of a -D flag).

allow_reservedbool, default=False

If False, names that shadow CPython or security-critical preprocessor guards are rejected.

Returns:
bool

True if the name is safe, False otherwise.

Parameters:
Return type:

bool

Notes

Valid macro names match the regex [A-Za-z_][A-Za-z0-9_]*. The reserved-name check is independent of syntax validity.

Examples

>>> is_safe_macro_name("MY_FLAG")
True
>>> is_safe_macro_name("Py_LIMITED_API")
False
>>> is_safe_macro_name("Py_LIMITED_API", allow_reserved=True)
True
>>> is_safe_macro_name("123INVALID")
False