Skip to content

1.7.1: revert dict | Model union return types from 1.7.0 (downstream-breaking regression)#34

Merged
jackparnell merged 1 commit intomainfrom
fix/return-type-regression
Apr 12, 2026
Merged

1.7.1: revert dict | Model union return types from 1.7.0 (downstream-breaking regression)#34
jackparnell merged 1 commit intomainfrom
fix/return-type-regression

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

The bug

1.7.0 introduced dict | Post (and similar union) return types on several read methods to advertise the new typed=True mode:

```python
def get_post(self, post_id: str) -> dict | Post: # 1.7.0
```

This broke every downstream consumer running strict mypy. They could no longer call `.get()` on the return value because mypy couldn't narrow the union:

```
src/langchain_colony/tools.py:223: error: Item "Post" of "dict[Any, Any] | Post" has no attribute "get" [union-attr]
```

Discovered while migrating smolagents-colony to colony-sdk 1.7.0 — got 77 mypy errors purely from the SDK type annotation change.

This is a SemVer violation: 1.6.0 → 1.7.0 was a minor bump but it broke type checking for every framework integration that uses the SDK with strict mypy.

The fix

Reverted the union return types to plain `dict` for backward compatibility. Runtime behaviour is unchanged — `typed=True` still wraps responses in the dataclass models at runtime; only the static type hints changed.

Typed-mode users who want strict static types should `cast(Post, ...)` at the call site:

```python
from typing import cast
from colony_sdk import ColonyClient, Post

client = ColonyClient("col_...", typed=True)
post = cast(Post, client.get_post("abc"))
print(post.title) # mypy now knows this is a Post
```

Affected methods

Sync + async:

  • `get_post`, `update_post`, `get_poll`
  • `send_message`
  • `get_me`, `get_user`
  • (async only) `create_comment`, `create_webhook`

Regression test

Added `TestReturnTypeAnnotations` in `tests/test_client.py` that pins the public method return annotations as the string literal `"dict"`. Anyone reintroducing the unions will get a clear failure.

Validation

  • 348 unit tests pass (was 346, +2 regression tests)
  • 100% line coverage
  • ruff check + format clean
  • mypy strict clean
  • Integration tests against live API still pass (16/16 v1.7.0 features tests) — confirms runtime is unchanged
  • CI matrix (Python 3.10/3.12/3.13)

Why this is a patch (not a minor)

No new features. No behaviour changes. Just fixing a SemVer-violating regression from 1.7.0. Once this lands and tags as v1.7.1, downstream framework repos can drop their workarounds (e.g. the per-module mypy override I had to add to smolagents-colony).

🤖 Generated with Claude Code

1.7.0 introduced ``dict | Post`` (and similar) return type annotations
on several read methods to advertise the new typed=True mode. This
broke every downstream consumer running strict mypy: they could no
longer call ``.get()`` on the return value because mypy couldn't
narrow the union.

This is a SemVer violation — minor versions shouldn't break things.
1.7.1 reverts the annotations to plain ``dict`` for backward
compatibility. Runtime behaviour is unchanged: typed=True still wraps
responses in dataclass models. Typed-mode users who want strict
static types should ``cast(Post, ...)`` at the call site:

    from typing import cast
    from colony_sdk import ColonyClient, Post

    client = ColonyClient("col_...", typed=True)
    post = cast(Post, client.get_post("abc"))
    print(post.title)

Affected methods (sync + async):
- get_post, update_post, get_poll, send_message, get_me, get_user
- create_comment, create_webhook (async only had unions on these)

Added a regression test (TestReturnTypeAnnotations) that pins the
public method return annotations as the string literal "dict" so we
don't reintroduce the unions. 348 unit tests pass, 100% coverage,
mypy clean. Verified against the live API via integration tests
(16 v1.7.0-features tests still pass — runtime unchanged).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jackparnell jackparnell merged commit 068ddc2 into main Apr 12, 2026
6 checks passed
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jackparnell jackparnell deleted the fix/return-type-regression branch April 12, 2026 10:41
Sign up for free to 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.

2 participants