flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[Python] generate enums as IntEnum or IntFlag type when requested

Open jtdavis777 opened this issue 1 month ago • 2 comments

Fixes #8617 and addresses #5083

This PR has enum types inherit from IntEnum or (IntFlag for bit_flags) directly, instead of just providing this as type hinting, and changes the setter function signatures to require enum types. This code should still be backward and forward compatible on receipt, as ints are still returned by the getters.

This code, chiefly, allows users to go to and from string string values to the enum values, but also provides some runtime type safety (over just type hint safety).

jtdavis777 avatar Nov 18 '25 03:11 jtdavis777

Some docs at least in docs/source/flatc.md would be nice for this change

fliiiix avatar Nov 18 '25 07:11 fliiiix

I played around a bit and it seemed fine, i couldn't integrated it into our main product because this crate was not updated yet https://github.com/rdelfin/flatbuffers-build/pull/30

fliiiix avatar Nov 18 '25 13:11 fliiiix

You said it was compatible.. do we need this flag at all? Can't we always do the better thing? so, I think it depends on what we mean by python 3 support. Now that we have dropped python 2 I think this is safe, but I believe technically this is python 3.4. Though TBF the current implementation is not consistent here so I think just doing this as part of --python-typing is fine. Will change to that!

jtdavis777 avatar Dec 07 '25 22:12 jtdavis777