Backblaze / b2-sdk-python

Python library to access B2 cloud storage.
Other
186 stars 61 forks source link

Feature Request: Typings #148

Open ehossack opened 4 years ago

ehossack commented 4 years ago

Request: Provide typings for python

Sufficient to support libraries like mypy. A starting point perhaps: https://mypy.readthedocs.io/en/stable/stubgen.html?highlight=generate

Not sure if this has already been considered, but I saw no record of it. It would also make using some of your APIs more intuitive, as I have a hard time discerning return types.

Thanks!

ppolewicz commented 4 years ago

@ehossack I understand why you are asking for this, but I don't understand why. We have documentation with type annotations for more than a year now. Now that 2.7 and 3.4 are out, we can move the type annotations from docstrings to nicer syntax, but almost everything is documented.

What would change for you if the typings were provided in Python 3.5-compatible manner?

ehossack commented 4 years ago

Hi sorry for the delay @ppolewicz

What would change is tooling like mypy would be able to recognize and check the type annotations. Docstrings is usable when reading/browsing, but sometimes they are incorrect, and do not enable automated tooling to verify the validity of your calls to the SDK.

Does that make sense?

ppolewicz commented 4 years ago

ok so your project uses mypy and you'd like to have warnings for improper calls to b2sdk?

ehossack commented 4 years ago

Yes. That's correct.

ppolewicz commented 4 years ago

All right, I now understand. The difficulty of work required to do this is not actually that high, the number of public interface classes is quite low (I'd say it's mostly B2Api, Bucket, sync and utils, maybe a couple of small classes like FileVersion).

Would you like to try to implement this @ehossack? It would be a really nice contribution. We'd then install mypy to make sure the types are correctly set inside b2sdk.

ehossack commented 4 years ago

Hi, I can potentially take this on, but have a couple other queued contributions to make first (will be at least a couple of weeks, if not more), so if anyone else sees this and wants to take in on first, please do so!

ehossack commented 4 years ago

@ppolewicz one thing I've noticed is that if this projects adds type annotations, it will be incompatible with 3.5 and below. Given the next release notes indicate the next version will drop support for 2.7 and 3.4, and that 3.5 is no longer supported after this month, is that compatible with the release plans?

If so, thinking about approaching this issue out loud:

ppolewicz commented 4 years ago

I think we've dropped support for 2.7 and 3.4 already, please talk with @mlech-reef about adding the linter, I'm not sure which stage would be appropriate

mlech-reef commented 4 years ago

Hi. Yes, python 2 and 3.4 are no longer supported on the master branch and we had been thinking about introducing mypy, but we put it not on the beginning of our list for CI/CD improvements. We wanted to focus first on a few other improvements which are already done and a few others which are not yet done, like:

Using typing and mypy would be great, but I have few concerns:

If you want to start working on that, I will be more than happy to support you if you need. The mypy linter can be added to the lint nox session in noxfile.py

mjurbanski-reef commented 1 year ago

This project has grown considerably since this was originally opened. A few of Python have been deprecated as well.

We are open to contributions adding type hints for old APIs.