fake-bpy-module icon indicating copy to clipboard operation
fake-bpy-module copied to clipboard

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

Open JonathanPlasse opened this issue 1 year ago • 6 comments

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

JonathanPlasse avatar May 15 '24 21:05 JonathanPlasse

@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.

nutti avatar May 27 '24 07:05 nutti

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

JonathanPlasse avatar May 27 '24 08:05 JonathanPlasse

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

nutti avatar May 27 '24 09:05 nutti

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

JonathanPlasse avatar May 27 '24 11:05 JonathanPlasse

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.

JonathanPlasse avatar Jun 03 '24 19:06 JonathanPlasse

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.

nutti avatar Jun 04 '24 09:06 nutti