testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

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

Open andres-ito-traversal opened this issue 1 month ago • 2 comments

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=https://github.com/testcontainers/testcontainers-python/issues/305

andres-ito-traversal avatar Nov 12 '25 18:11 andres-ito-traversal

@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

andres-ito-traversal avatar Nov 12 '25 18:11 andres-ito-traversal

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: 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           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Nov 14 '25 13:11 codecov[bot]