Skip to content

Bug: waiting_for is incorrectly type annotated #889

Closed

Description

@eteran

Describe the bug

waiting_for currently is annotated as returning "DockerContainer", but it really should be annotated as returning Self.
This is important because the incorrect annotation loses type information.

To Reproduce

Most type checkers will complain about assigning a DockerContainer to a variable of type MySqlContainer because of this

container: MySqlContainer = MySqlContainer("mysql:5.6", root_password="root").waiting_for(
            CompositeWaitStrategy(
                PortWaitStrategy(3306),
                LogMessageWaitStrategy("mysqld: ready for connections"),
            )
        )

Runtime environment

$ uname -a
Linux DESKTOP-971PGRM 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
$ python3 -V
Python 3.12.7
$ pip list | grep testcontainers
testcontainers                    4.13.1

Checkers such as Astral's ty and pyright complain.

Activity

  1. alexanderankin commented on Oct 2, 2025

    @alexanderankin
    Member

    if you submit the PR I will merge, is it literally just this one line?

    diff --git a/core/testcontainers/core/container.py b/core/testcontainers/core/container.py
    index f0882a4..dcf576e 100644
    --- a/core/testcontainers/core/container.py
    +++ b/core/testcontainers/core/container.py
    @@ -169,7 +169,7 @@ class DockerContainer:
                 return self.with_kwargs(platform="linux/amd64")
             return self
     
    -    def waiting_for(self, strategy: WaitStrategy) -> "DockerContainer":
    +    def waiting_for(self, strategy: WaitStrategy) -> Self:
             """Set a wait strategy to be used after container start."""
             self._wait_strategy = strategy
             return self
  2. alexanderankin commented on Oct 2, 2025

    @alexanderankin
    Member

    otherwise i need to get another maintainer involved usually takes longer

  3. eteran commented on Oct 2, 2025

    @eteran
    ContributorAuthor

    I think it is essentially just that one line 👍🏻 (perhaps and added import if needed).

    I'm about to head to bed, but I can make a PR for it tomorrow.

  4. added a commit that references this issue on Oct 2, 2025
  5. eteran commented on Oct 2, 2025

    @eteran
    ContributorAuthor

    Actually, it was trivial and I test that it appeases pyright, so I've submitted a PR. Thanks for the quick response!

  6. added 2 commits that reference this issue on Oct 2, 2025
  7. alexanderankin commented on Oct 7, 2025

    @alexanderankin
    Member

    let me know if its still an issue on new release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions