TypeTranslator¶
Note
Generated from the C++ headers by apiary --emit-cpp-docs-json.
-
std::string translate_python_default(const std::string &cpp_default)¶
Best-effort translation of a captured default-argument expression to its Python-literal form.
- Parameters:
cpp_default – The captured C++ default-argument expression text.
- Returns:
The Python-literal form of the default. Strips integer/float suffixes, rewrites
nullptr/std::nullopttoNone,true/falsetoTrue/False, and falls back to the verbatim text when no rewrite applies.
-
std::string translate_python_type(clang::QualType type, const clang::ASTContext &ctx)¶
Best-effort Python-stub form of
type, suitable for emission in a.pyifile consumed by pyright.Note
Anything unknown (most notably bound class types) is returned as the canonical qualified C++ name; a post-pass over the IR resolves those against bound classes.
- Parameters:
type – The Clang type to translate.
ctx – The AST context owning
type.
- Returns:
The Python-stub form of the type. Maps fundamentals to Python builtins, std containers/optional/pair/tuple/variant/function to their typing equivalents, and strips cv/ref/ptr qualifiers.
-
std::string translate_python_type_string(const std::string &cpp_type)¶
String-based variant of
translate_python_typefor callers that already have a printed C++ type name.- Parameters:
cpp_type – The printed C++ type name (no
clang::QualTypeaccess required).- Returns:
The Python-stub form of the type. Same recursion rules: maps fundamentals,
std::vector<T>→list[T_py],std::pair<A,B>→tuple[A_py, B_py], etc.
-
std::string translate_type(clang::QualType type, const clang::ASTContext &ctx)¶
Returns a pretty-printed C++ form of
typesuitable for emission in pybind11 binding code.Note
Phase-2 stub: currently relies on Clang’s own PrintingPolicy; Phase 3 will extend this to handle holder rewrites (e.g. unique_ptr<T> -> shared_ptr<T> when an APIARY_HOLDER directive is in effect) and pybind11-specific type substitutions.
- Parameters:
type – The Clang type to translate.
ctx – The AST context owning
type.
- Returns:
A pretty-printed C++ form of the type.