Skip to content

fix: add PEP 561 py.typed markers for type checker support - #918

Closed
andres-ito-traversal wants to merge 1 commit into
testcontainers:mainfrom
andres-ito-traversal:andres/add-type-stubs
Closed

fix: add PEP 561 py.typed markers for type checker support#918
andres-ito-traversal wants to merge 1 commit into
testcontainers:mainfrom
andres-ito-traversal:andres/add-type-stubs

Conversation

@andres-ito-traversal

@andres-ito-traversalandres-ito-traversal commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Summary

Adds py.typed marker files to all testcontainers packages to comply with PEP 561 and enable type checking support.

Motivation

Without py.typed markers, type checkers like Pyright and mypy report "Stub file not found" errors when importing testcontainers modules, even though the code has inline type annotations.

Changes

  • Added py.typed marker to core/testcontainers/
  • Added py.typed markers to all module packages under modules/*/testcontainers/
  • Updated pyproject.toml to ensure py.typed files are included in distributions

Testing

Verified that type checkers no longer report missing stub file errors:

pyright -c "from testcontainers.postgres import PostgresContainer"# 0 errors, 0 warnings, 0 informations

Impact

  • Enables proper type checking for projects using testcontainers
  • No breaking changes or runtime behavior modifications
  • Aligns with Python packaging best practices (PEP 561)

Github Issue=#305

@andres-ito-traversalandres-ito-traversal changed the title Add PEP 561 py.typed markers for type checker supportfix: add PEP 561 py.typed markers for type checker supportNov 12, 2025
@andres-ito-traversal

Copy link
Copy Markdown
ContributorAuthor

@rnorth Apologies richard for the random tag, but do you have any idea how authors will get notified of this PR? It's my first time contributing to this open-source library

 Add py.typed marker files to core and all module packages to indicate
type information is available. This enables type checkers like Pyright
and mypy to recognize and validate type hints in testcontainers packages.
Resolves "Stub file not found" errors when running type checkers on
code that imports testcontainers modules.
@codecov

codecovBot commented Nov 14, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.78%. Comparing base (5853d32) to head (468ede5).

Additional details and impacted files
@@ Coverage Diff @@## main #918 +/- ##
=======================================
Coverage 79.78% 79.78% =======================================
Files 14 14 Lines 1182 1182 Branches 184 184 =======================================
Hits 943 943 Misses 197 197 Partials 42 42 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tranquility2

Copy link
Copy Markdown
Contributor

Already done as part of #1045

Sign up for freeto 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.

3 participants

@andres-ito-traversal@Tranquility2@alexanderankin