nutti / fake-bpy-module

Fake Blender Python API module collection for the code completion.
MIT License
1.31k stars 95 forks source link

String Enum type should be a union of literal instead of str #216

Open JonathanPlasse opened 1 month ago

JonathanPlasse commented 1 month ago

Description about the feature

In Blender API, there are enum string type, currently the type used is str | int and ideally should only be str (c.f. #213). Even better would be that the type is a union of possible literal string variant. For example the return type of bpy.types.Operator.execute() is Screenshot from 2024-05-15 23-00-24 The type would be Literal["RUNNING_MODAL"] | Literal["CANCELLED"] | Literal["FINISHED"] | Literal["PASS_THROUGH"] | Literal["INTERFACE"].

Are you willing to contribute about this feature. (Yes/No)

Yes

nutti commented 1 month ago

@JonathanPlasse

I assigned this issue to you. Do you have an idea about this? I think this is difficult for our approach to realize this.

JonathanPlasse commented 1 month ago

If the RST contain the link to the enum page in the return type (e.g. Operator Return Items), it should be feasible. Otherwise, it will be difficult.

image

nutti commented 1 month ago

I think it is difficult to parse other RST files while processing the document. If you have an idea, I will remain this issue. Or, I will close this issue. What do you think? @JonathanPlasse

JonathanPlasse commented 1 month ago

I would like to take a deeper look to implement it.

JonathanPlasse commented 1 month ago

When encountering an rna enum reference we could parse on the fly the corresponding rst file. Screenshot from 2024-06-03 21-51-08 Screenshot from 2024-06-03 21-51-40

I will see if I can make it work.

nutti commented 1 month ago

Thank you. This needs to support to read related files from somewhere.

I'm wondering this should be done in transformer or analyzer phase. https://github.com/nutti/fake-bpy-module/tree/master/src/fake_bpy_module/analyzer https://github.com/nutti/fake-bpy-module/tree/master/src/fake_bpy_module/transformer

I think adding this feature into the transformer phase is much simpler and easy to maintenance in future.