nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
3.03k stars 435 forks source link

type stubs #1434

Closed KotlinIsland closed 1 year ago

KotlinIsland commented 2 years ago

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.

nedbat commented 2 years ago

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.

KotlinIsland commented 2 years ago

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

KotlinIsland commented 2 years ago

While I'm here should I implement black?

nedbat commented 2 years ago

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?

KotlinIsland commented 2 years ago

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)
andersk commented 2 years ago

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.

nedbat commented 1 year ago

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.

KotlinIsland commented 1 year ago

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