pybind / pybind/pybind11

None support in builtin casters

Open
#940 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Currently, it's not possible to pass None to arithmetic casters, e.g.

m.def("is_none", [](const int* x) { return !x; });

would not accept a None (unlike class_-defined types).

This also applies to other builtin casters -- e.g. it doesn't work for std::string*, but does for const char* (due to how the caster works).

As one potential solution, it may be nice to have py::arg().none(true) affect these cases as well (or allow None by default, like it is for user-bound types).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the builtin arithmetic and std::string* caster paths described in the issue, comparing them with class_-defined types and const char*. Determine whether py::arg().none(true) or default acceptance is intended; done means the examples accept None consistently and relevant behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.