azure-sdk-for-python: Mypy doesn't work with azure-storage-blob

  • Package Name: azure-storage-blob
  • Package Version: 12.8.1
  • Operating System: Ubuntu 20.04
  • Python Version: 3.8.10

Describe the bug If I want to use mypy to statically type check my Python code it fails to find the type information of the azure.storage.blob, despite that there are type comments in the module.

To Reproduce Steps to reproduce the behavior:

  1. pip install azure-storage-blob==12.8.1 mypy==0.910
  2. echo "from azure.storage.blob import ContainerClient" > test.py
  3. mypy test.py
    test.py:1: error: Skipping analyzing "azure.storage.blob": found module but no type hints or library stubs
    test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
    Found 1 error in 1 file (checked 1 source file)
    

Expected behavior I expect mypy to find the type hints in the module.

Additional context

There seem to be type annotations in the code. I asked in the https://gitter.im/python/typing chat and was told that the issue is that there isn’t a py.typed file in the package, which seems to be true, since I can’t find it in lib/python3.8/site-packages/azure/storage/blob

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Now 12.9.0 has been released with the still-broken typing, so users who pick up the latest package and run mypy over their code are exposed to this.

/home/dch/.virtualenvs/atm-controller/lib/python3.8/site-packages/azure/storage/blob/_serialize.py:129: error: Type signature has too many arguments
/home/dch/.virtualenvs/atm-controller/lib/python3.8/site-packages/azure/storage/blob/_blob_client.py:1407: error: Type signature has too few arguments

Many thanks for that PR and the issue to validate all packages; much appreciated.

as for the py.typed file we added it to our MANIFEST starting 12.9.0b release, so you should be able to run mypy without having to create that file yourself manually. Could you please confirm this?

Not sure if this question was for me… I don’t fully understand what you are asking.

We are not doing anything manually. Everything was working perfectly up to 12.8.1 — mypy was happily checking our codebases and was blissfully ignoring azure-storage-blob.

Then I guess you had py.typed added in 12.9.0 (even though the typings were bad) and mypy started failing after upgrading azure-storage-blob. Again, we didn’t do anything manually other than upgrading azure-storage-blob to 12.9.0.

None of the workarounds people suggested in the various issues relating to this works for us. The following, for example, makes no difference at all:

[mypy-azure.storage.blob.*]
ignore_errors = True

So our options are either sticking with 12.8.1 until all typing issues are fixed, or disabling mypy for the entire codebase 🙁

That’s why I suggested earlier potentially getting a release out without py.typed, and only add it back when types are actually working.

@polys that’s a good suggestion, I will discuss with our team if we can remove the typed file until mypy is fully validated.

I feel a bit bad about getting all of this started with my original issue after seeing how much trouble it caused 🙈

Hi @rnestler

Sorry for the delay. Thanks for the pr! It looks great!