sighingnow / libclang

(Unofficial) Release libclang (clang.cindex) on pypi.
https://pypi.org/project/libclang
Other
85 stars 23 forks source link

Missing return type annotation (multiple instances) #49

Open fskoras opened 1 year ago

fskoras commented 1 year ago

method parse should be annoted to return TranslationUnit image

property cursor should be annotated to return Cursor class image

I just gave 2 examples but there are many more instances where return type annotations would be helpful (especially while prototyping the code because without those PyCharm autocomplete is not working properly)

JhnW commented 1 year ago

I hope the maintainer of the project won't be offended by a bit of self-promotion. The fact is that type hints are missing in many places, but even if they were, it won't improve your quality of life. I was going through it. Why? It's good that you ask. This is due to the structure of the clang parser, which in 99% of cases returns two very generic types of cursors that you have to recognize each time by the kind field. I don't know what code you need, but you can take a look at my devan project. I rely on libclang (at the type level) wrapping all those ugly cursor kind in nice type information plus throw in some clang filler with a bit of regex magic.

fskoras commented 1 year ago

I'm trying to create a kind of source code Amalgamation that will consist of functions and declarations of global variables. The output of the tool must be self-contained, so the type definitions must also be resolved and sorted in the correct order. For this I use a topological sort algorithm. You can check out my repository if you're interested. I must confess that working on this project turned out to be more difficult than I initially imagined.

But I'm getting off topic. Just wanted to suggest an improvement to an already great package. Of course, it's up to the repository maintainer if he/she cares about such minor nuances.