coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

type stubs

Open KotlinIsland opened this issue 3 years ago • 6 comments

I would like some type stubs for coverage, I see that you support >= 3.7 so types in the code would be possible (although perhaps not desirable).

I'm happy to drive this. just need to know if you want the stubs inline or in a separate package, or maybe even hosted on typehsed.

KotlinIsland avatar Aug 09 '22 05:08 KotlinIsland

I'd be interested in adding annotations right into the code. I'd been using pycontracts as a pre-historic way of checking types, but that package is unmaintained and is causing pain.

If there are annotations, I want to run mypy, so we'd need some new tooling for that too.

nedbat avatar Aug 16 '22 20:08 nedbat

Sounds cool, I'll give it a shot and make a PR, would you be interested in basedmypy?

KotlinIsland avatar Aug 16 '22 23:08 KotlinIsland

While I'm here should I implement black?

KotlinIsland avatar Aug 17 '22 00:08 KotlinIsland

That's generous of you, but I don't want black for this repo, thanks. I don't know anything about basedmypy, but I'm guessing I don't want that either, but maybe I'm wrong?

nedbat avatar Aug 17 '22 00:08 nedbat

It's basically a fork of mypy with additional functionality. basedmypy:

def foo(a=1)
    print(a)

mypy:

def foo(a: int = 1) -> None:
    print(a)

KotlinIsland avatar Aug 17 '22 01:08 KotlinIsland

For projects that use coverage as a library (such as test runners), it would be better if the type annotations worked with standard mypy and didn’t require a custom fork.

andersk avatar Aug 30 '22 21:08 andersk

I've started adding annotations. About 3/4 of the coverage/*.py files now check cleanly. Please let me know if I should do something differently.

nedbat avatar Jan 02 '23 17:01 nedbat

@nedbat this is awesome! One outstanding task is to add a 'py.typed' file. See #1550

KotlinIsland avatar Feb 02 '23 03:02 KotlinIsland