EntilZha / PyFunctional

Python library for creating data pipelines with chain functional programming
http://pyfunctional.pedro.ai
MIT License
2.41k stars 132 forks source link

Another typing attempt #199

Closed FlavioAmurrioCS closed 5 months ago

FlavioAmurrioCS commented 6 months ago

Pull Request: Enhance Typing Support for Library

I've been a fan of this library for quite some time, but I've eagerly awaited proper typing support. After reviewing other pull requests, I noticed that some were abandoned or contained extensive changes. With that in mind, I've kept this pull request concise and focused.

Key Updates:

  1. Typing Information: I've primarily added type hints for the most commonly used methods, particularly within the sequence class.
  2. No Logic Changes: Rest assured, there are no alterations to the existing logic.
  3. Configuration Updates:
    • Added pre-commit-config.yaml with Black formatting, mypy type checking, and ruff. (If possible please enable https://pre-commit.ci/ for this repo)
    • Adjusted settings in pyproject.toml for mypy and ruff, enabling only a select few rules to avoid excessive modifications.
  4. Added remove_none: this will remote None values from stream as well as TypeGuard the stream.
  5. Simple Type Testing: In order to "test" the typing annotation I went ahead and called all the examples from the a functions docs and assigned it to a variable that has been typed with the expected type. Is there is a mismatch, mypy would flag this. This helped me debug typing bugs.

I hope this contribution aligns with the project's goals and makes it easier for everyone to work with! 🚀

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 99.61538% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 98.24%. Comparing base (6ed2e9a) to head (59cf0e4).

Files Patch % Lines
functional/streams.py 96.15% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #199 +/- ## ========================================== + Coverage 98.12% 98.24% +0.11% ========================================== Files 12 13 +1 Lines 2350 2452 +102 ========================================== + Hits 2306 2409 +103 + Misses 44 43 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

EntilZha commented 6 months ago

Thanks for the persistence! I took a quick lookover PR and initially it looks good. I'll take a second look once the tests are passing. It would be great to get the code cov tests passing, but if there is a good reason they wouldn't pass due to lower coverage, then thats fine, wouldn't be a blocker.

FlavioAmurrioCS commented 6 months ago

@EntilZha I went ahead configured pytest-cov to ignore TYPE_CHECKING blocks and ellipses. https://github.com/nedbat/coveragepy/issues/831#issuecomment-517778185 so hope things should be good now.

maestro-1 commented 6 months ago

Hello @FlavioAmurrioCS Made any progress on this?

FlavioAmurrioCS commented 6 months ago

This PR is ready for review. I am just waiting for feedback or an approval at this point. I do have more changes for the remaining files but didn't want to add too much to this PR to prevent it from being too large. cc: @EntilZha @maestro-1

EntilZha commented 5 months ago

Sorry for the delay, was traveling! LGTM to merge and passes all the test now. Thanks so much for pushing this across the finish line!