wenkokke / py-tree-sitter-type-provider

Type providers for tree-sitter in Python.
MIT License
3 stars 1 forks source link

Question: Actual Python source code generation #93

Open smheidrich opened 1 week ago

smheidrich commented 1 week ago

I realize this would be something more appropriate for a GitHub Discussions thread, but Discussions seem disabled for this project, so I'm asking here instead:

The README gives an example of what a generated module looks like as Python code, but am I correct in my understanding that output in this form isn't supported and modules can only be created as their runtime representation?

Output as actual Python source code to be placed in .py files on disk would allow using them with static type checkers like Mypy or Pyright, hence the question.

If this is not supported, I guess a workaround would be to go through the dataclasses contained in the runtime module one by one, using the information in fields like __annotations__ and __mro__ to reconstruct their Python sources, but I'm not yet sure whether this wouldn't run into other issues.

wenkokke commented 1 week ago

I've generated and updated the mypy type declarations for my packages using mypy's stubgen which has generally worked.

smheidrich commented 1 week ago

Hmm, doesn't seem to work for me :thinking:

To ensure it's not an issue specific to my project, I also tried it with your py-tree-sitter-talon project, but even there, if I delete the existing dynamic.pyi and run any of

stubgen src/tree_sitter_talon                   # variant 1
stubgen -p tree_sitter_talon                    # variant 2
stubgen -m tree_sitter_talon._internal.dynamic  # variant 3

it always ends with out/tree_sitter_talon/_internal/dynamic.pyi remaining empty. If I add --inspect-mode to force runtime inspection, the result is the same for the -m variant, while for the others it crashes with some weird Mypy-internal error...

What am I missing? :thinking:

wenkokke commented 1 week ago

I genuinely don't recall what stubtest commands I ran to generate the type declarations, unfortunately.