python-amazon-paapi icon indicating copy to clipboard operation
python-amazon-paapi copied to clipboard

Bug: Type hints not working as expected

Open YPCrumble opened this issue 2 years ago • 1 comments

Steps to reproduce

  1. Check out this example repository: https://github.com/YPCrumble/amazon-paapi-test
  2. Create a virtualenvironment and install mypy
  3. Run mypy . and you should get this following error:
example/example.py:1: error: Skipping analyzing "amazon_paapi.models.item_result": module is installed, but missing library stubs or py.typed marker
example/example.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
example/example.py:5: note: Revealed type is "Any"

Current behavior MyPy type hints are not being picked up from the package

Expected behavior I would expect the revealed type of result to be Item, and I would expect MyPy to raise an error for the subsequent statement, print(result.item_info.content_info), because item_info.content_info could be None per my previous commit, so item_info.content_info.publication_date can potentially raise an AttributeError.

YPCrumble avatar Sep 23 '22 16:09 YPCrumble

This is the relevant section of the MyPy docs as to why this might be happening: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker

YPCrumble avatar Sep 23 '22 16:09 YPCrumble