Skip to content

--check-untyped-defs-lite #7744

Closed
Closed
@belm0

Description

@belm0

This is a feature request for a mechanism allowing projects to benefit more from partial typing-- for example, typing of commonly used API's. (I envision it as a "lite" version of --check-untyped-defs.)

use case

We have a project where there is a core API written by software engineers, while the bulk of the application uses those API's and is written by non-specialists (animators, researchers, etc.). (I don't think this scenario is uncommon.)

So far we only employ type hints sparingly, as a convenience for IDE autocompletion. For us, mypy is used merely to check for typos and syntax errors on the type annotations themselves.

We aren't motivated to add type hints to our common API's because mypy won't use that information unless the API usage sites themselves have type annotations. But it's not feasible for the non-specialist application authors to write and maintain such annotations.

So I would like to see mypy offer a way to use info from typed API's as much as possible (say to the extent of type inference available at the usage sites), without requiring annotations at the usage sites.

proposal

Add an option --check-untyped-defs-lite which will:

  • like --check-untyped-defs, enable type checking on code which does not have type annotations
  • but will limit checks and/or error output of said unannotated code to uses of API's having type annotations. For example:
    • access of unknown attribute foo.bar in typed module foo
    • call of typed function foo.baz() with incorrect number of arguments
    • call of typed function foo.baz() with incorrectly typed arguments (as far as can be inferred at the call site)
    • typed mismatch when assigning result of typed function foo.baz() to a variable of known type

So unlike --check-untyped-defs, --check-untyped-defs-lite will never emit errors such as "Need type annotation for ..." and "Cannot determine type of ...".

summary

This feature would allow an untold number of projects to benefit from using mypy even without having type annotations in their own code. It would strongly motivate more API's to be type annotated-- both 3rd party and a project's own common API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions