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

Support for mypy #116

Open
7 of 12 tasks
binaryDiv opened this issue Apr 17, 2024 · 0 comments
Open
7 of 12 tasks

Support for mypy #116

binaryDiv opened this issue Apr 17, 2024 · 0 comments
Labels
enhancement Improvements to existing features or smaller new features refactoring Code refactoring, clean up and other code maintenance work. testing Related to testing (e.g. unit tests)
Milestone

Comments

@binaryDiv
Copy link
Contributor

binaryDiv commented Apr 17, 2024

This issue consists of two major parts: First, integrate mypy as a static type checker in the dev and build process of the library (and fix issues that mypy finds). Second, try to find out how to make validataclass compatible with mypy (i.e. in projects that use validataclass and mypy).

Use mypy to check the library code

  • Add mypy to the dev environment (tox, Makefile) as an optional step for now.
    • Only add /src to the target files for now, but add a comment to add /tests later too.
    • (The tests will probably require the full validataclass-mypy compatibility.)
  • Fix all low-hanging fruit issues detected by mypy (some issues might need a bit more work)
  • Try to fix the more complicated issues (if necessary, mark them as # type: ignore for now, maybe create issues for them)
  • When all issues are resolved or ignored, make mypy a required (i.e. default) step in the Tox config.
  • Integrate mypy into the test and build CI pipelines
  • Fix typing issues in the unit tests that are not related to how typing in validataclasses works (don't permanently add /tests to the mypy config yet)

Make validataclass fully mypy-compatible

  • Make package PEP 561 compatible: PEP 561 compatibility (py.typed) and explicit re-exports #125
  • Run mypy on validataclass example code (e.g. the unit tests) and examine the issues.
    • Assigning validators to fields in validataclasses: foo: int = IntegerValidator() - it's a validator, not an int.
    • Subclasses of validataclasses with incompatible field type overrides (e.g. subclass changes field type from int to OptionalUnset[int])
    • Sentinels: Checking x is not UnsetValue does not narrow down the type, and evaluating as boolean if x: doesn't either. (For the latter: would it help to declare the type of UnsetValueType.__bool__ as Literal[False]?)
  • Write mypy plugin.
  • ???
  • Tests and documentation
    • Document how to use mypy with validataclass (best practices etc.)
@binaryDiv binaryDiv added enhancement Improvements to existing features or smaller new features testing Related to testing (e.g. unit tests) refactoring Code refactoring, clean up and other code maintenance work. labels Apr 17, 2024
@binaryDiv binaryDiv added this to the 1.0.0 Release milestone Apr 17, 2024
binaryDiv added a commit that referenced this issue Apr 30, 2024
This isn't really a fix since we're just ignoring the line, however, in this case we can make a safe assumption that the typing is correct.
binaryDiv added a commit that referenced this issue Apr 30, 2024
…ators

According to OOP principles, overriding the return type of validate() in a subclass in an incompatible way (e.g. date is not a subclass of str) is not allowed. However, with our validators it absolutely makes sense to use base validators and convert their output to different types (e.g. string to date).
binaryDiv added a commit that referenced this issue Apr 30, 2024
binaryDiv added a commit that referenced this issue Apr 30, 2024
Integrate mypy into development process (part of #116)
binaryDiv added a commit that referenced this issue May 6, 2024
Add unit tests to mypy targets; fix typing in tests (part of #116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features or smaller new features refactoring Code refactoring, clean up and other code maintenance work. testing Related to testing (e.g. unit tests)
Projects
None yet
Development

No branches or pull requests

1 participant