Skip to content

fix(core): Typing in docker_client - #702

Merged
alexanderankin merged 4 commits into
testcontainers:mainfrom
Tranquility2:typed_docker_client
May 4, 2025
Merged

fix(core): Typing in docker_client#702
alexanderankin merged 4 commits into
testcontainers:mainfrom
Tranquility2:typed_docker_client

Conversation

@Tranquility2

Copy link
Copy Markdown
Contributor

Supports: #305
Related : #691#692#700

Based on #504, kudos @alexanderankin

poetry run mypy --config-file pyproject.toml core/testcontainers/core/docker_client.py Success: no issues found in 1 source file

Old

 Error Summary ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py │ 12 │
│ core/testcontainers/core/docker_client.py │ 14 │
│ core/testcontainers/core/image.py │ 17 │
│ core/testcontainers/core/waiting_utils.py │ 8 │
│ core/testcontainers/core/container.py │ 20 │
│ core/tests/test_new_docker_api.py │ 4 │
│ core/tests/test_docker_in_docker.py │ 2 │
│ core/testcontainers/compose/compose.py │ 22 │
│ core/testcontainers/compose/__init__.py │ 2 │
│ core/tests/test_version.py │ 2 │
│ core/tests/test_ryuk.py │ 2 │
│ core/tests/test_registry.py │ 1 │
│ core/tests/test_image.py │ 3 │
│ core/tests/test_compose.py │ 7 │
└───────────────────────────────────────────┴────────┘
Found 116 errors in 14 files.

New

 Error Summary ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py │ 12 │
│ core/testcontainers/core/network.py │ 3 │
│ core/testcontainers/core/image.py │ 17 │
│ core/testcontainers/core/waiting_utils.py │ 8 │
│ core/testcontainers/core/container.py │ 19 │
│ core/tests/test_new_docker_api.py │ 4 │
│ core/tests/test_docker_in_docker.py │ 2 │
│ core/testcontainers/compose/compose.py │ 22 │
│ core/testcontainers/compose/__init__.py │ 2 │
│ core/tests/test_version.py │ 2 │
│ core/tests/test_ryuk.py │ 2 │
│ core/tests/test_registry.py │ 1 │
│ core/tests/test_image.py │ 3 │
│ core/tests/test_compose.py │ 7 │
└───────────────────────────────────────────┴────────┘
Found 104 errors in 14 files.

@codecov

codecovBot commented Sep 16, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@e9e40f9). Learn more about missing BASE report.

Additional details and impacted files
@@ Coverage Diff @@## main #702 +/- ##
=======================================
Coverage ? 84.97% =======================================
Files ? 12 Lines ? 679 Branches ? 106 =======================================
Hits ? 577 Misses ? 79 Partials ? 23 

☔ 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.

@Tranquility2Tranquility2 changed the title fix(core): Typed docker_clientfix(core): Typing in docker_clientSep 16, 2024
@Tranquility2

Tranquility2 commented Nov 16, 2024

Copy link
Copy Markdown
ContributorAuthor

Please note:

core/testcontainers/core/config.py:46: error: X|YsyntaxforunionsrequiresPython3.10 [syntax]
connection_mode: str|None=environ.get("TESTCONTAINERS_CONNECTION_MODE")

Found when rebasing and updated to support 3.9 (I'm not aware of deprecating 3.9 in tc-python, feel free to update)

@Tranquility2

Copy link
Copy Markdown
ContributorAuthor

@alexanderankin@kiview can you please rerun this? (I assume this was an issue with the docker registry)

@CarliJoyCarliJoy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use cast only when required (i.e. for dict[str, Any]).

If possible always improve the runtime type safety.

Comment threadcore/testcontainers/core/docker_client.py Outdated
Comment threadcore/testcontainers/core/docker_client.py Outdated
Comment threadcore/testcontainers/core/docker_client.py Outdated
Comment threadcore/testcontainers/core/docker_client.py
Comment threadcore/testcontainers/core/config.py Outdated
This is true for everything but bridge mode.
"""
if self == self.bridge_ip:
if cast(str, self) == self.bridge_ip:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ifcast(str, self)==self.bridge_ip:
ifself==self.bridge_ip:

That is neither required nor correct.

The original code does not issue any Typing Errors:
Not in mypy nor pyright

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CarliJoy Mypy seems to disagree:
image

@Tranquility2Tranquility2Mar 15, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to latest mypy, still the same behavior
mypy 1.15.0 (compiled: yes)

@Tranquility2Tranquility2Mar 15, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the issue :)
under "[tool.mypy]" on pyproject.toml
we have strict = true
image

I'll be adding # type: ignore[comparison-overlap] in the relevant locations (future PRs) @CarliJoy

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self == ConnectionMode.bridge_ip:

Seems to be the type correct solution.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix after #807 as it also touch this part :)

@Tranquility2

Tranquility2 commented Mar 8, 2025

Copy link
Copy Markdown
ContributorAuthor

@CarliJoy apricate you taking the time to comment :) I'll be happy to fix and update as suggested.
I assume/hope #700 & #701 will go in first so I'll know we are really rolling with this track.

@Tranquility2

Tranquility2 commented Mar 15, 2025

Copy link
Copy Markdown
ContributorAuthor

@CarliJoy Updated with all of the Fixes

@alexanderankin
alexanderankin merged commit e8bf224 into testcontainers:mainMay 4, 2025
alexanderankin pushed a commit that referenced this pull request Jun 16, 2025
🤖 I have created a release *beep* *boop*
---
##
[4.11.0](testcontainers-v4.10.0...testcontainers-v4.11.0)
(2025-06-15)
### Features
* **core:** Protocol support for container port bind and expose
([#690](#690))
([a0d4317](a0d4317))
* DockerContainer initializer to accept its private members as kwargs
([#809](#809))
([e7feb53](e7feb53))
### Bug Fixes
* **compose:** use provided docker command instead of default
([#785](#785))
([0ae704a](0ae704a))
* **core:** Add kwargs to image build
([#708](#708))
([cc02f94](cc02f94))
* **core:** change with_command type to include list of strings
([#789](#789))
([f7c29cb](f7c29cb))
* **core:** Determine docker socket for rootless docker
([#779](#779))
([6817582](6817582))
* **core:** Typing in docker_client
([#702](#702))
([e8bf224](e8bf224))
* **core:** Typing in generic + network
([#700](#700))
([2061912](2061912))
* **core:** Typing in version
([#701](#701))
([9dc2a02](9dc2a02))
* **core:** wait in test core registry
([#812](#812))
([b574c0e](b574c0e))
* **modules:** fix cosmosdb failure
([#827](#827))
([dafcbed](dafcbed))
* **modules:** update chroma version
([#826](#826))
([b7d41dd](b7d41dd))
* **rabbitmq:** correct pika pypi reference
([#817](#817))
([e90d308](e90d308))
* **registry:** module typed
([#811](#811))
([6b11268](6b11268))
* use connection mode override function in config
([#775](#775))
([ab2a1ab](ab2a1ab)),
closes
[#774](#774)
---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Tranquility2@CarliJoy@alexanderankin