[FEAT] Automatic conversions for C++ type-aliases.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
I have a bunch of type aliases in my library, which alias std::string and int. For example:
using SomeName = std::string;
These are used as arguments or return types in classes and functions. For example:
class SomeClass {
public:
SomeClass(SomeName name) {}
};
When I bind the class above using pybind11, the Python interpreter doesn't recognise SomeName as a new type, but binds it to a Python string instead (see the two snippets below).
py::class_<SomeClass>(m, "SomeClass")
.def(py::init<SomeName>();
>> help(SomeClass)
Help on class SomeClass in module some_module:
class SomeClass(pybind11_builtins.pybind11_object)
...
| Methods defined here:
| __init__(...)
| __init__(self: some_module.SomeClass, arg0: str) -> None
~~~
...
It's quite easy to create aliases in Python (e.g. SomeName = str). Is it possible to add a feature that automatically creates type-aliases in Python, based on the c++ type-aliases, and show the correct type names in the method description?
I considered using custom type casters, but that doesn't allow me to cast two (or more) aliases that alias the same type.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name any files, tests, or implementation entry points. Begin by reviewing how pybind11 exposes C++ argument and return types to Python, then define how aliases should be represented and verified in generated help output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100