rolling icon indicating copy to clipboard operation
rolling copied to clipboard

Add type stubs across project

Open OutSquareCapital opened this issue 3 months ago • 1 comments

Overview

  • Added typing signatures for all public classes
  • Added Literals for Tracker and WindowType for convenient autocompletion
  • Deleted redundant and costly runtime isinstance check for arguments types in base class since the LSP and types checker will flag it
  • Added some typing for internal variables and functions

Notes

I used Any in a lot of situation since the docstrings and the internal implementations weren't in conflict with this.

However with some guidance I could change this very easily. I assume that most of the time floats and int are expected in the stats functions for example, henceforth this could easily be changed, and would also allow a way easier conversion into a faster implementation (numba, cython, or may I say Rust)?

Making the classes generics to hint the return type (int->int, float->float, int|float -> float in Sum) would be for example the natural next step.

Also I haven't run pytest, since I haven't changed any actual runtime code, only added annotations, this shouldn't have changed anything.

My test was just to run a quick script at the root to ensure that no import conflict error were created

Happy to hear feedback and contribute more, because I will use this lib in my own project https://github.com/OutSquareCapital/pychain and made some similar works here https://github.com/OutSquareCapital/rustats which could help as a base example of how to reimplement the code here in Rust

OutSquareCapital avatar Sep 17 '25 23:09 OutSquareCapital

Thank you very much for this PR!

Adding type annotations to this project has been at the back of my mind for a while.

I'll hopefully have a chance to review this properly soon.

ajcr avatar Sep 18 '25 20:09 ajcr