Skip to content

Question about type signature for "don't know" #3712

@thanatos

Description

@thanatos

This is presently just a question, but perhaps it is a feature request.

As I'm annotating functions in a pre-existing codebase, I have found that I tend to have two distinct things that I'd like to annotate:

  • This function takes objects of any type as input
  • This function takes objects of a particular type as input, but I have absolutely no idea what that type is.

mypy has the Any type; presently, my assumption is that this is intended for the first bullet. I've been abusing it for the second bullet as well, but this means that if I come back to the signature later, I have no idea if the Any means "anything" or "dunno".

Does mypy have a better "Unknown" type? Would it be recommended to just say,

Unknown = Any

?

(I think most ideally, I could, perhaps with a flag like --flag-unknowns, ask mypy to emit warnings about uses of something like "Unknown".)

(In case you're wondering/thinking "just don't annotate it for the unknown case", I try to do that, but this mostly comes up with dicts where I know the key's type (usually, str) but not the values — e.g. Dict[str, ???], or in functions, where I know some of the args but not all of the arguments — e.g. (int, str, str, str, ?, ??, ???) -> Thing —, and I'd like to document and ideally get mypy's type-checking support for what I know.)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions