pypa / pyproject-hooks

A low-level library for calling build-backends in `pyproject.toml`-based project
https://pyproject-hooks.readthedocs.io/
MIT License
122 stars 49 forks source link

Type annotate the public API #167

Closed pradyunsg closed 11 months ago

pradyunsg commented 1 year ago

Closes #90

takluyver commented 1 year ago

Thanks @pradyunsg - it looks like @layday has already done a detailed review of the annotations, so I'll skip doing that.

My inclination is to be fairly conservative with Python version support, since this is meant to be a boring piece of low-level infrastructure that doesn't change often. I see pip hasn't dropped 3.7 support yet, so I'd suggest we don't here either. But I'm not going to argue about this if you really want to.

layday commented 1 year ago

https://github.com/pypa/build/pull/601

pradyunsg commented 1 year ago

The latest commit makes it possible to do...

if TYPE_CHECKING:
    from pyproject_hooks import SubprocessRunner

And then annotate subprocess runners using that type.

pradyunsg commented 1 year ago

Instead of leaving that as a comment, I've gone ahead and documented that.

henryiii commented 1 year ago

Wouldn’t it make sense to allow SubprocessRunner at runtime on Python 3.8+? So this interface oddity will go away once 3.7 is dropped? Another idea (if it’s not runtime checkable) is to just make it a dummy object at runtime, so downstream code isn’t forced into extra TYPE_CHECKING checks.

layday commented 1 year ago

That's what we do with the IsolatedEnv in build, it's a simple ABC at runtime on Python 3.7.

pradyunsg commented 11 months ago

On the basis of "this is better than status quo", I'm gonna go ahead and merge this.

There's a couple of potential follow ups to improve this further:

pradyunsg commented 11 months ago

(I'll fix the documentation build separately)