Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul type hints with beartype and PEP 585 compliance #559

Closed
wants to merge 23 commits into from

Conversation

MilesCranmer
Copy link
Owner

@MilesCranmer MilesCranmer commented Mar 3, 2024

This implements the following:

  1. Sets up beartype runtime type checking for the entire package
    • I use the configuration that type errors => warnings. I don't want to break anything if a type is incorrect but still works; just want to let the user know a type is unexpected.
    • This runtime type checking seems pretty fast, so speed shouldn't be an issue.
    • (thanks @PatrickKidger for mentioning beartype; it is lovely!)
    • BearType is not available on Python <3.8 so I only include the install on Python 3.8+
  2. Updates type symbols to the PEP 585 standards.
  3. Moves various stages of processing the data (like converting pandas -> numpy; getting column names; feature selection) into dataclasses so improve readability/robustness. The dataclasses have frozen=True so I can be sure they are not modified by other functions.

TODO:

  • Only use beartype during testing rather than during runtime.
  • Possibly revert | as shorthand for Union or see if there's any way to get that behavior from future
  • Implement a from future import __annotations__ call where the new type syntax is used

@MilesCranmer
Copy link
Owner Author

Still not sure this should be on by default or not... Perhaps we just set it up for testing.

@MilesCranmer
Copy link
Owner Author

(Implemented in #748)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant