pybind / pybind/pybind11

Scoped enums and arithmetic

Open
#2,221 10 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

Issue description

arithmetic isn't working for scoped enums.

Reproducible example code

If I have
enum_<ScopedEnum>(m, "ScopedEnum", arithmetic{})
.value("Value1", ScopedEnum::Value1)
...

then in python
ScopedEnum.Value1 | ScopedEnum.Value1
it throws error unsupported operand type(s) for |: 'int' and 'ScopedEnum'

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 with the reproducible enum_(..., arithmetic{}) example and trace pybind11's scoped-enum arithmetic handling; the issue names no file or test. Done means ScopedEnum.Value1 | ScopedEnum.Value1 no longer raises the reported operand-type error, with regression coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.