apple / app-store-server-library-python

MIT License
168 stars 31 forks source link

Missing py.typed file causes type checkers to ignore type annotations #15

Closed WFT closed 1 year ago

WFT commented 1 year ago

Hi, thanks for the great package! I'm already using it to explore migration from verifyReceipt.

The core issue is this:

$ pip3 install app-store-server-library
$ pip3 install mypy
$ cat test.py
import appstoreserverlibrary as aslib

print(aslib.models.Environment.PRODUCTION)
$ mypy test.py
test.py:1: error: Skipping analyzing "appstoreserverlibrary": module is installed, but missing library stubs or py.typed marker  [import]
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)

I believe the issue is that while this project includes type annotations (which is great), it is missing the py.typed file. That tells mypy and other type checkers to treat it as having type annotations. You can find details either in PEP 561:

Package maintainers who wish to support type checking of their code MUST add a marker file named py.typed to their package supporting typing. This marker applies recursively: if a top-level package includes it, all its sub-packages MUST support type checking as well.

or in mypy's documentation:

If you would like to publish a library package to a package repository yourself (e.g. on PyPI) for either internal or external use in type checking, packages that supply type information via type comments or annotations in the code should put a py.typed file in their package directory.

alexanderjordanbaker commented 1 year ago

@WFT Could you please test with 0.2.1 in pypi-test when you have a chance and see if the issue is resolved?

WFT commented 1 year ago

Just checked it out. Looks like it works perfectly. This can be closed.

WFT commented 1 year ago

(Looks like the test file in the original doesn't actually typecheck due to some typos; here's one that does)

import appstoreserverlibrary.models.Environment

print(appstoreserverlibrary.models.Environment.Environment.PRODUCTION)
$ mypy test.py
Success: no issues found in 1 source file
WFT commented 1 year ago

Thanks @alexanderjordanbaker