-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typings for mypy #71
Comments
I am not quite sure what you want. Pivy is generated with swig. So maybe you should look into swig-docs to see if there is such a feature. |
So, there's this provisional standard in Python 3.5, PEP-484 Type Hints. It's based on PEP 3107 -- Function Annotations syntax (Python 3.0) and allows you to define types for static analysis, so that type checking can be used to catch bugs at build-time in IDE and using a It's especially suitable for C++ python bindings, since C++ is inherently strictly typed language. To define types for bindings, you provide a stub file, with *.pyi extension. So, what I want is this set of *.pyi files to be provided with It looks like it is supported via autodoc: http://swig.org/Doc3.0/Python.html#Python_nn67 But it's not quite the same. Somebody has already requested this feature in the swig repo on GH: swig/swig#735 Would you be willing to provide stub files in the pip package if I were to code them manually? |
the pip packages are not updated. we use conda, and other system package-manager. There is the possibility to create wheels from conda-packages, but I am not sure this is the best way to proceed. |
Well, by "pip package" I meant "to be installable using |
we recently updated to cmake. so it would be best if you will use this configuration for any additional features. |
So it doesn't use distutils anymore? Could you please update README? https://github.com/coin3d/pivy/blob/master/README.md |
It should work with both (cmake or distutils). But I guess cmake will be the future as it is consistent with the rest of the coin-tools. I added some instructions: c7854b7 |
found this here: pythonocc-core uses also swig. So it might be interesting to know how these files are created. edit: some more insights tpaviot/pythonocc-core#789 |
As far as I understood: In the following PR this pythonocc-generator was enriched with a capability to generate *.pyi files in addition to SWIG *.i files: In pivy, as far as I see, SWIG files are not generated but are rather coded manually. So no, pythonocc approach is not applicable without heavy reengineering. Another approach is using I see there was an attempt to do so here: Manual coding. This is the most robust but the most time consuming approach. Stubgen This looks promising: https://mypy.readthedocs.io/en/stable/stubgen.html But of course it is just a draft for manually edited files. It lacks proper types and has no documentation. MonkeyType https://github.com/Instagram/MonkeyType This is the most advanced generator that infers types. But it requires runtime usage. That is the code is actually run, not statically analysed. So you need a good test coverage. Out of those, I would go for a combination of manual coding with some generator which would parse out the Doxygen documentation |
thanks for the research. Monkeytype sounds like a very nice way to 1. increase test coverage and 2. get typings. Currently there are not many tests. But I will try monkeytype in the next days. |
I've tried the CppHeaderParser. It works, but unfortunately, API documentation is located at the *.cpp files rather than in header files and CppHeaderParser can't parse out doxygen comments out of method implementation. The practice of putting API documentation to cpp files rather than header files appears to be for the sake of avoiding rebuilds when updating documentation. Yeap, C++ sucks. It appears the only way is to use Doxygen's XML output. MonkeyType wouldn't work well, as python docstrings currently only contain type annotations, not the C++ descriptions. |
Here's a CppHeaderParser approach. Requires
|
The main issue is that C++ types don't quite map to Python types. Python lacks the assignment operator override. Also, some setValues are mapped manually. It means there are a lot of errors like this:
Have no idea how to fix those so far. The SWIG interface files (*.i) do not provide any declarative mechanism for that. |
So what is the conclusion? |
Maybe some hybrid solution.
But I don't have enough experience with Coin to determine the right mappings. Also the issue is that even if you do it manually, you can't quite mimic automatic type conversion that is implemented in C++. For example, this:
can only be implemented like this:
If you rather specify
Still need to investigate how it works in runtime. |
Here's what I have so far: TODO:
|
any progress on this @Vanuan? can we already include this in the packages? |
@looooo Coin is a massive library. I couldn't make much progress on generating typings. Only stubs so far, which should be edited manually to match C++ types to corresponding Python types. I appreciate your interest and everything you do to maintain Coin/Pivy. Currently, my hope is that there's more interest in Coin. To do that, I've tried to update the README page: coin3d/coin#439 You're doing a tremendous work by maintaining this library. Keep it up. |
My latest progress is here: |
@Vanuan thanks for your work on this issue. Whenever you think we should integrate something into pivy / pivy-packages, please ping me. |
Is there any chance pivy typings could be provided without too much effort? Or maybe such a typing package already exists?
E.g. like this
The text was updated successfully, but these errors were encountered: