Library of Assembled Shared Sources
lass::python::PyExportTraitsMaybeNone< T > Struct Template Reference

Helper class to create PyExportTraits for MaybeNone wrapped types. More...

#include <export_traits.h>

Inheritance diagram for lass::python::PyExportTraitsMaybeNone< T >:

Detailed Description

template<typename T>
struct lass::python::PyExportTraitsMaybeNone< T >

Helper class to create PyExportTraits for MaybeNone wrapped types.

MaybeNone does not provide any runtime or compile-time checks. It only serves to alter the type-hint to T | MaybeNone in Python, which is useful for type-checking, see The Any Trick.

MaybeNone<T> types can only be returned from C++ to Python, it doesn't make sense to pass them as function parameters to C++.

Use this helper to create PyExportTraits for your own MaybeNone wrapped types by inheriting from it.

template <typename T, template <typename, typename> class S, typename C>
struct PyExportTraits< MaybeNone< util::SharedPtr<T, S, C> > >: public PyExportTraitsMaybeNone< util::SharedPtr<T, S, C> >
{
constexpr static const char* py_typing = "T | MaybeNone"; // optional
};
Wrapper to type-hint return values in Python that maybe None but not likely.
Definition maybe_none.h:82
general utility, debug facilities, ...
Helper class to create PyExportTraits for MaybeNone wrapped types.
by copy, general case assumes shadow type or PyObjectPlus based type.

Built-in specializations are provided for raw pointers T*, util::SharedPtr<T>, std::shared_ptr<T>, and std::optional<T>.

Note
If you use typename T as the main template parameter for your actual type, then the Python type will automatically be deduced. If not, or if you still see a T | None type-hint, you can can override the py_typing member to specify the type-hint you want.
See also
MaybeNone
PyExportTraits<MaybeNone<T*>>
PyExportTraits<MaybeNone<util::SharedPtr<T,S,C>>>
PyExportTraits<MaybeNone<std::shared_ptr<T>>>
PyExportTraits<MaybeNone<std::optional<T>>>

Definition at line 695 of file export_traits.h.


The documentation for this struct was generated from the following file: