jazzband / dj-database-url

Use Database URLs in your Django Application.
https://pypi.org/project/dj-database-url/
BSD 3-Clause "New" or "Revised" License
1.49k stars 205 forks source link

Inline types are not exposed to users #214

Closed AlexWaygood closed 1 year ago

AlexWaygood commented 1 year ago

Hi!

I'm a maintainer over at typeshed, where we have stubs for dj-database-url. It looks like you recently added inline types and a py.typed file, which is great! This means that we can hopefully soon remove our stubs from typeshed.

Unfortunately, your py.typed file isn't properly exposing your inline types to users of the package. If I install dj-database-url==1.3.0 and run mypy on a file containing just this:

import dj_database_url

Then this is the output from mypy:

repro.py:1: error: Library stubs not installed for "dj_database_url"  [import]
repro.py:1: note: Hint: "python3 -m pip install types-dj-database-url"
repro.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
repro.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)

The reason for this is that dj-database-url is currently a single-file project. Unfortunately, PEP 561 doesn't provide a way for single-file projects to add a py.typed file to their project. In order for the py.typed file to be recognised by type checkers, you'd need to convert this project into a package (with the py.typed file inside the package). If you did that (and specified package_data in setup.py to ensure that the file was included in uploads to PyPI), then type checkers would see the py.typed file, and know to look for inline types in dj-database-url.

Would you consider making dj-database-url into a package? If dj-database-url remains a single-file project, then unfortunately the py.typed file you already have in this repo serves little purpose, and may as well be deleted :/

Cc. @palfrey, who authored #198, and @XF-FW, who originally contributed the stubs to typeshed :)

palfrey commented 1 year ago

Sounds good to me. https://github.com/jazzband/dj-database-url/pull/215 implements this, and explicitly tests the mypy test case works. @mattseymour?

mattseymour commented 1 year ago

Fixed as of release 2.0.0

AlexWaygood commented 1 year ago

Thanks @palfrey and @mattseymour! Can confirm that the py.typed file is now included in the PyPI release, which led to our typeshed automation successfully being triggered: https://github.com/python/typeshed/pull/10094