Skip to content

TODO: optionally (or always?) reformat as per-line arg type comments? #4

Open
@anentropic

Description

@anentropic

currently we output a single-line type comment:

def my_func(arg1, arg2, arg3):
    # type: (arg1T, arg2T, arg3T) -> returnT

this can get quite long, but even Black will never wrap this comment line

if not all args have documented types then currently we add a type comment which doesn't match the signature, alternatively we should introspect the signature and raise an error

another alternative is to re-format the def and type comment as:

def my_func(
    arg1,  # type: arg1T
    arg2,  # type: arg2T
    arg3,  # type: arg3T
):
    # type: (...) -> returnT

this is better when the comment gets too long

additionally, say arg2 was not typed in the docstring, we can output:

def my_func(
    arg1,  # type: arg1T
    arg2,
    arg3,  # type: arg3T
):
    # type: (...) -> returnT

if we simply omit the arg from our one-line type comment, mypy would rightly give us:

error: Type signature has too few arguments

but with the multi-line format mypy appears to treat the missing annotation as an implicit Any and will happily type check it as that

Currently if there are missing args we output:

  # type (...) -> returnT

i.e. all args become implicit Any. mypy accepts this, but it's not a good annotation

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions