cloudpipe / cloudpickle

Extended pickling support for Python objects
Other
1.65k stars 167 forks source link

Adoption of type-hints #541

Open priba opened 3 months ago

priba commented 3 months ago

The adoption of type-hints is becoming popular in the python community. Are there plans to add type hints within cloudpickle?

ogrisel commented 2 months ago

I have no strong opinion on this matter but I am worried about the extra maintenance effort. How would you benefit from cloudpickle using type-hints? Do you use cloudpickle as a library in another library that uses type-hints?

aldanor commented 2 months ago

Having cloudpickle in any type-verified project (e.g. using mypy) results in errors like

cloudpickle: module is installed, but missing library stubs or py.typed marker [import-untyped]

forcing you to add cloudpickle to type-ignore list in pyproject.toml, which isn't nice.

Also, having type annotations in the library itself may prevent some downstream user errors (e.g. they will have their ide/editor highlight type mismatches if any).

aldanor commented 2 months ago

but I am worried about the extra maintenance effort.

I don't think there's too much maintenance effort - it's basically adding type annotations around all public-facing functions/methods/types, and then adding an empty py.typed file.

For bonus points, you'd want to run mypy in CI to make sure that type annotations are internally consistent.

priba commented 2 months ago

Agree with @aldanor, he explained my current issues.

I am adding cloudpickle into type-ignore so mypy does not complain. I assume several people are dealing with this.

ogrisel commented 2 weeks ago

I don't think there's too much maintenance effort - it's basically adding type annotations around all public-facing functions/methods/types, and then adding an empty py.typed file.

We can indeed start with a minimal PR that adds type annotations to the public API of cloudpickle only and later decide if we want to generalize type annotations to private functions/methods for follow-up PRs.

If there are any volunteer in the room, feel free to open a PR for the first part.