pyreadstat icon indicating copy to clipboard operation
pyreadstat copied to clipboard

Type hints via PYI files?

Open nachomaiz opened this issue 5 months ago • 5 comments

Over time I've been building PYI type stubs for the functions & metadata objects I use the most from pyreadstat.

Would it be helpful to upstream them into the repo? Let me know, happy to open a PR with suggestions. 😄

Thank you for one of the most helpful libraries in my arsenal!

nachomaiz avatar Jul 29 '25 14:07 nachomaiz

sounds interesting! I am open to it, but let's wait for the file object PR to be ready first, as I guess it would change the hints ...

ofajardo avatar Oct 14 '25 13:10 ofajardo

Sounds good! I'm also looking forward to the support for file objects. I'll hold off until it lands. Thanks! 😁

nachomaiz avatar Oct 17 '25 16:10 nachomaiz

btw, I was researching a little bit if it is possible to add the annotations directly in the pyx file, and as far as I understood mypy for instance can only use information from py or pyi files and not pyx or compiled code, is my understanding correct or do you know if somehow the annotatations could go directly in the cython code?

ofajardo avatar Nov 19 '25 10:11 ofajardo

Yeah that's my understanding as well.

Annoyingly most language servers also don't recognize docstrings from cython (though they do show up through inspect.signature) so I sometimes end up copying over the docstrings too, maybe setting up a script to do so on release.

Usually I go for combining the above with setting up cython to also include .pyx and .pxd files in the build so the full code is available, and hopefully some day type checkers will support them too. I think the latter also helps when cimporting.

nachomaiz avatar Nov 20 '25 10:11 nachomaiz

Hmm I was not aware of the docstrings issue. Another alternative would be to transform pyreadstat.pyx to a .py file, I guess then we would have annotations and docstrings. If the performance would not be much affected, I think it could be a good solution.

ofajardo avatar Nov 22 '25 08:11 ofajardo