sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
238 stars 49 forks source link

Add thorough numpy type hints #109

Closed TheTripleV closed 1 year ago

TheTripleV commented 1 year ago

Might fix #89 .

  1. Add more thorough detection of numpy usage for inserting the import numpy statement. If any module has replace_numpy_array global classname replacement applied to it, that module will now have import numpy added to the stubs.

  2. Optionally (with cli flag) generate hints with the nptyping library. This library provides typing support for numpy included typing both the size and dtype in a way that Pylance doesn't error on. The existing numpy _Size hints generate a typing error.

sizmailov commented 1 year ago

With #112, it's possible to apply type transformations in a more controlled manner and not even think about imports (almost).

I'm closing the PR since it targets an obsolete library version.

The suggested feature should be implemented similarly to the following class:

FixTypingExtTypeNames https://github.com/sizmailov/pybind11-stubgen/blob/a1cd5faab09e642d4c0692474790ca737a271baf/pybind11_stubgen/parser/mixins/fix.py#L398-L458