rtree icon indicating copy to clipboard operation
rtree copied to clipboard

Type hinting for the code

Open samgans opened this issue 5 years ago • 7 comments

Hello!

I think it'll be useful to add type hints to the python code here to make it more self-documented and clearly expressed. If you think that this is a good idea, I can take the task and make this myself.

samgans avatar Oct 27 '20 07:10 samgans

I'm enthusiastic about the type hints, but I don't know what minimum Python version that would end up causing Rtree to be limited to. Does support degrade smoothly back to Python 3.6?

hobu avatar Oct 27 '20 13:10 hobu

@hobu, I think yes, the compatibility with older versions will be dropped upon the creation of the hinting system. Maybe if the support of older python needed, the string hints can be written (which are compatible with type checkers such as mypy).

samgans avatar Oct 27 '20 14:10 samgans

Type hints were first added to Python 3.5. There have been a lot of improvements since then, but if you need to maintain support for Python 3.5 or 3.6, it shouldn't be hard to do. There are ways to support older versions of Python too by adding the type hints in comments.

adamjstewart avatar Jan 28 '22 05:01 adamjstewart

If someone wants to make a PR adding these, I would be happy to merge it.

hobu avatar Feb 04 '22 15:02 hobu

@samgans I'm adding type hints to many (but not all) functions/classes in #215. Let me know if you want to help. I can also finish the major classes and let you handle the details in a follow-up PR if that works better.

adamjstewart avatar Feb 17 '22 21:02 adamjstewart

#215 has now been merged. There's definitely still a lot of functions that need type hints added to them, but the majority of user-facing functions now have type hints. @samgans feel free to add more and I'll review!

adamjstewart avatar Feb 20 '22 17:02 adamjstewart

I'm very excited for type annotations for Rtree - thanks for all the work so far. Unfortunately I noticed that Mypy gave some warnings with the v1.0.0 Rtree. I just opened https://github.com/Toblerity/rtree/pull/243 as I think would fix that issue - @hobu @adamjstewart let me know what you think or if you have other thoughts on how to ensure Rtree type annotations work properly in user projects. Thanks!

oderby avatar Apr 18 '22 12:04 oderby