Skip to content

Support for mypy #116

@binaryDiv

Description

@binaryDiv

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to existing features or smaller new featuresrefactoringCode refactoring, clean up and other code maintenance work.testingRelated to testing (e.g. unit tests)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions