Implementing bitflags (enum.Flag) support.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
I would love to see some support on bitflags, or flag support in general.
This is important due to having an API that needs to use bitflags, and as we would prefer to not have a "wrapper" library of sorts, this would simply be nice.
Another reason for it being implemented is that enum.Enum has already been implemented, and would be nice to have all features that relate to that library implemented.
Finally, I have some ideas of implementation, which would similarly match, how the bitflag crate does it, or how the bitflags does it (and I have used this crate before)
I much prefer the first crates (bitflag) implementation, so something like
#[pyflag] // <-- maybe optional, or pre-detected `enum.IntFlag` detection? or a repr of some kind...
#[pyo3(rename_all = "SCREAMING_SNAKE_CASE")]
enum Fruits {
Apple = 1 << 0,
Banana = 1 << 1,
Carrot = 1 << 2,
}
Which would look something like the following in python:
class Fruits(enum.IntFlag):
APPLE = 1 << 0
BANANA = 1 << 1
CARROT = 1 << 2
The rust implementation would of course need to support all the bitflag features as well, like addition, subtraction, etc.
This is something I would be more than happy to implement, however I am not at all familiar with FFI or any internal things of pyo3, only the external things.
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
Start by reviewing PyO3's existing enum.Enum support and the bitflag and bitflags crate behavior referenced in the issue. Clarify the intended Python IntFlag interface and the complete set of bitflag operations before implementation; done should provide the requested flag support without requiring a wrapper library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100