flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[Python] Improve python API

Open satur9nine opened this issue 1 month ago • 4 comments

  • Make the Python API similar to Rust and Swift for improved usability

satur9nine avatar Nov 16 '25 21:11 satur9nine

@satur9nine I've got this on my list! Will look it over sometime in the next few days 🤞

jtdavis777 avatar Nov 24 '25 23:11 jtdavis777

@fliiiix this seems like a good improvement but as always I enjoy an extra opinion :D

jtdavis777 avatar Dec 02 '25 00:12 jtdavis777

I had a quick look can you also split up this change in multiple commits but on MR is fine? (You can just force push them on this MR) I really like the usage :sparkles: One thing im either not seeing or is missing is the generation of these new functions in the pyi files.

fliiiix avatar Dec 02 '25 16:12 fliiiix

I had a quick look can you also split up this change in multiple commits but on MR is fine? (You can just force push them on this MR) I really like the usage ✨ One thing im either not seeing or is missing is the generation of these new functions in the pyi files.

OK I split it up into multiple commits. Do you know how to confirm the .pyi files are correct? I usually run mypy for files that have inline type information. Maybe it is similar for pyi files.

satur9nine avatar Dec 03 '25 05:12 satur9nine

I'm away for the next few days and i didn't manage to review this in detail but it seems ok enough to get merged and if there are problems we can deal with them later :shrug:

Do you know how to confirm the .pyi files are correct?

Visual inspection of the pyi file and then there is a way if they are in the correct location mypy will also pick them up. I realized when i looked again at this change that the types are now in the py file and the pyi file if im not mistaken the types should end up only in the pyi files. (I would not remove them in this MR from the py file, and i need to look up the discussion again about that topic, but i think that should be a new MR)

fliiiix avatar Dec 03 '25 15:12 fliiiix

I'm away for the next few days and i didn't manage to review this in detail but it seems ok enough to get merged and if there are problems we can deal with them later 🤷

Do you know how to confirm the .pyi files are correct?

Visual inspection of the pyi file and then there is a way if they are in the correct location mypy will also pick them up. I realized when i looked again at this change that the types are now in the py file and the pyi file if im not mistaken the types should end up only in the pyi files. (I would not remove them in this MR from the py file, and i need to look up the discussion again about that topic, but i think that should be a new MR)

Thanks for looking I will try to find some time this weekend to patch up the types.

satur9nine avatar Dec 05 '25 00:12 satur9nine

I'm away for the next few days and i didn't manage to review this in detail but it seems ok enough to get merged and if there are problems we can deal with them later 🤷

Do you know how to confirm the .pyi files are correct?

Visual inspection of the pyi file and then there is a way if they are in the correct location mypy will also pick them up. I realized when i looked again at this change that the types are now in the py file and the pyi file if im not mistaken the types should end up only in the pyi files. (I would not remove them in this MR from the py file, and i need to look up the discussion again about that topic, but i think that should be a new MR)

Thanks for looking I will try to find some time this weekend to patch up the types.

The only .py file I see that has python types is MonsterExtra.py file, but that is apparently because the monster extra is some kind of special test that runs with a different command that includes --python-typing: Command '['flatc', '--cpp', '--gen-compare', '--csharp', '--cs-gen-json-serializer', '--reflect-names', '--gen-mutable', '--gen-object-api', '--no-includes', '--java', '--kotlin', '--python', '--python-typing', '--python-decode-obj-api-strings', 'monster_extra.fbs', 'monsterdata_extra.json']'

Did you see types in some other .py file?

satur9nine avatar Dec 05 '25 05:12 satur9nine