Skip to content

build(deps): Type docker-py with types-docker #2603

Closed

Description

@dan-petty

Problem or Motivation

docker-py 7.2.0 has no type hints, so every import of it in src carries # type: ignore[import-untyped]. Nine of the 51 markers under the src type: ignore ceiling are these imports (docker/engine.py, sandbox/host.py, commands/docker.py). Because the ceiling is at its value, new code cannot import docker-py's reference parser (docker.utils.parse_repository_tag, docker.auth.resolve_repository_name), so #1997 splits image references with its own 10 lines.

Proposed Solution & Architectural Design

Target Subsystem

src/devops_cli/docker/, pyproject.toml, tests/test_architectural_invariants.py.

Existing Tool Considered

typeshed's types-docker stubs, maintained with typeshed. Nothing new is built; the change deletes ignores and the split of #1997.

Acceptance criteria

  • uv run mypy src passes with types-docker installed, and the src type: ignore ceiling is lower than 51.
  • No # type: ignore[import-untyped] names a docker-py module.
  • tagged_image in docker/registry.py uses docker-py's parser, and its table tests still pass.

Proposed design

Problem statement

docker-py 7.2.0 ships no type hints, so nine imports in src carry # type: ignore[import-untyped] markers. The src type: ignore ceiling sits at 51, its value, so new code cannot import docker-py's reference parser. This blocks #1997 from using docker-py's parse_repository_tag and resolve_repository_name, forcing a 10-line hand-rolled split in registry.py. Adding typeshed's types-docker stubs removes the nine markers, frees ceiling budget, and lets registry.py use the typed parser.

Acceptance criteria

Requirement: mypy passes with types-docker

uv run mypy src SHALL pass with types-docker installed and no new errors in src/devops_cli/docker/engine.py.

Scenario: mypy run after adding types-docker

  • WHEN types-docker is in the dev dependencies and the three errors in engine.py are fixed
  • THEN uv run mypy src exits with code 0

Requirement: ceiling lowered

The src type: ignore ceiling in tests/test_architectural_invariants.py SHALL be lower than 51.

Scenario: ceiling value check

  • WHEN the nine docker-py import-untyped markers are removed
  • THEN DEFAULT_SUPPRESSION_CEILINGS['src type: ignore'] is 42

Requirement: no docker-py import-untyped markers

No # type: ignore[import-untyped] marker in src SHALL name a docker-py module.

Scenario: scan for docker-py import-untyped

  • WHEN the codebase is scanned for type: ignore[import-untyped] comments
  • THEN no comment names a docker, docker.utils, docker.errors, docker.constants, docker.transport, or docker.context module

Requirement: registry uses docker-py parser

tagged_image in src/devops_cli/docker/registry.py SHALL use docker-py's parse_repository_tag and resolve_repository_name to split a reference.

Scenario: tagged_image calls docker-py parser

  • WHEN tagged_image is called with a valid reference such as ghcr.io/org/img:tag
  • THEN the function calls docker.utils.parse_repository_tag and docker.auth.resolve_repository_name and returns the same TaggedImage as before

Requirement: registry table tests pass

The existing table tests of tagged_image SHALL pass after the parser change.

Scenario: table test run

  • WHEN pytest runs the tagged_image table tests in tests/
  • THEN all table test cases pass with the same expected TaggedImage values

Existing Tool Considered

typeshed's types-docker (7.2.0.20261006) covers the need of typing docker-py 7.2.0 imports. It lacks docker.context.api.get_current_context_name, which requires one remaining type: ignore marker.

Key questions

  • Which open, maintained tool or library covers the need of typing docker-py imports?: typeshed's types-docker (7.2.0.20261006) provides type stubs for docker-py 7.2.0. It lacks docker.context.api.get_current_context_name. [sources: pyproject.toml, src/devops_cli/docker/engine.py:393]
  • How to fix the mypy error at engine.py line 261 where create_api_error_from_http_exception expects requests.HTTPError but the code passes Exception?: Narrow the except clause from Exception to requests.HTTPError, matching the stub's signature. (best practice) [sources: src/devops_cli/docker/engine.py:261]
    • Chosen: Narrow except to requests.HTTPError. The stub types create_api_error_from_http_exception with a requests.HTTPError parameter. Narrowing the catch matches the stub and removes the need for a type ignore.
    • Rejected: Keep except Exception and add a type ignore. Rejected because it adds a marker to the ceiling instead of removing one.
  • How to fix the mypy error at engine.py line 315 where DockerClient does not match the EngineClient Protocol (5 member conflicts)?: Align the Protocols in src/devops_cli/docker/sdk.py with the types-docker stubs so that DockerClient satisfies EngineClient. (best practice) [sources: src/devops_cli/docker/engine.py:315, src/devops_cli/docker/sdk.py]
    • Chosen: Align Protocols in sdk.py with the stubs. The body states this approach. It removes the 5 conflicts at the source and keeps the Protocol as the seam for fakes.
    • Rejected: Add type ignores for the 5 conflicts. Rejected because it adds five markers to the ceiling instead of removing nine.
  • How to handle the mypy error at engine.py line 393 where the stubs have no docker.context.api.get_current_context_name?: Keep one # type: ignore[import-untyped] marker on that import, since the stub genuinely lacks the name. (best practice) [sources: src/devops_cli/docker/engine.py:393]
    • Chosen: Keep one type ignore for the missing name. The body states this approach. The stub lacks the name, so a single targeted marker is the correct suppression.
    • Rejected: Remove the call and use an alternative. Rejected because get_current_context_name is the only way to read the current context name from docker-py's config, and no alternative exists in the stubs.
  • What is the new src type: ignore ceiling after removing the nine docker-py markers?: 42, which is 51 minus the nine removed markers. [sources: tests/test_architectural_invariants.py, src/devops_cli/docker/engine.py]
  • Which parser should tagged_image in registry.py use to split a reference?: docker-py's parse_repository_tag and resolve_repository_name, now typed by types-docker. (best practice) [sources: src/devops_cli/docker/registry.py, openspec/changes/archive/2026-10-29-1997-argo-image-pin-drift/proposal.md]
    • Chosen: Use docker-py's parse_repository_tag and resolve_repository_name. The body states this approach. With types-docker installed, the import is typed and adds no marker. It replaces the 10-line hand-rolled split.
    • Rejected: Keep the 10-line hand-rolled split. Rejected because the whole purpose of this item is to use the typed parser and free ceiling budget.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/refactor
    status/new
    value/medium
    effort/medium
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/refactor. The change adds type stubs, fixes type errors, and removes ignore markers without altering runtime behaviour.
    • Priority: P2-Medium. It unblocks new docker-py imports at the ceiling but does not fix a user-facing defect.
    • Value: Medium. It raises type safety and unblocks developer work but has no direct end-user effect.
    • Effort: Medium. It requires adding a dependency, fixing 3 type errors, deleting 9 markers, lowering a ceiling, and refactoring one function.
    • Related: fix(deps): pyproject.toml declares every package src imports, and a deptry step in devops ci keeps it that way #1120, which asks for a different change. Both touch pyproject.toml dependencies, but 1120 ensures every imported package is declared while this adds type stubs and cleans up ignore markers.
  3. added
    priority/p2-medium
    type/infra
    scope/deps
    and removed
    type/refactor
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 07fb4c2 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch build/2603-type-docker-py-with-typeshed-s, draft pull request #3071. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Add types-docker to dev dependencies: 4485 tokens
    2. Fix the 3 mypy errors and remove unused ignores: 4574 tokens
    3. Lower the src type: ignore ceiling to 42: 4473 tokens
    4. Use docker-py's parser in tagged_image: 4517 tokens

    These paths of the plan are no file on the default branch, and no group creates them: tests/test_architectural_invariants.py. A person checks that the plan names them right.

  7. added 4 commits that reference this issue on Nov 1, 2026
  8. added
    status/planned
    and removed
    status/ready
    on Nov 1, 2026
  9. changed the title [-]build(deps): type docker-py with typeshed's types-docker, and drop its type: ignore markers[/-] [+]build(deps): Type docker-py with types-docker[/+] on Nov 6, 2026
  10. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 78 characters, and the limit is 60. The type and the scope stay.

  11. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 6, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 6, 2026
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

    effort/mediumpriority/p2-mediumscope/depssource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions