Skip to content

Add a py.typed file, to make types available downstream - #2314

Merged
tim-schilling merged 1 commit into
django-commons:mainfrom
brianhelba:py-typed
Feb 20, 2026
Merged

Add a py.typed file, to make types available downstream#2314
tim-schilling merged 1 commit into
django-commons:mainfrom
brianhelba:py-typed

Conversation

@brianhelba

Copy link
Copy Markdown
Contributor

Description

This will not change any behavior of this package, but it is required for consuming projects to read any existing type information here.

This file is required to exist and should be empty. There's no alternative mechanism. See: https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/

This follows #2227.

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

This will not change any behavior of this package,
but it is required for consuming projects to read
any existing type information here.

This file is required to exist and should be empty. There's no alternative mechanism.
See: https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/

This follows django-commons#2227.
@tim-schilling

Copy link
Copy Markdown
Member

If we don't have everything using type annotations, is that going to cause problems for someone using mypy?

@brianhelba

brianhelba commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

If we don't have everything using type annotations, is that going to cause problems for someone using mypy?

No, not at all, it'll be the same as someone with local code / functions that aren't fully typed. In short, MyPy will infer untyped things as typing.Any. Indeed, this is already how MyPy downstream is perceiving everything in django-debug-toolbar, since we lack py.typed. The addition of this file will be strictly additive, allowing types to be used from this package where they do exist.

Personally, I think it's a nuisance that PEP 561 makes us include this, but it's just become a routine practice.

Also, note that hatchling.build will include py.typed in sdists without any additional configuration.

@tim-schilling

Copy link
Copy Markdown
Member

Thank you for that explanation @brianhelba! I'll merge this once the docs/linter passes.

@tim-schilling
tim-schilling merged commit 0d35dee into django-commons:main Feb 20, 2026
27 checks passed
@github-actions

Copy link
Copy Markdown

Coverage report

This PR does not seem to contain any modification to coverable code.

@brianhelba
brianhelba deleted the py-typed branch February 20, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants