Skip to content

fix(typing): annotate the __init_subclass__ hooks, which strict type checkers refuse to call untyped - #168

Merged
earakely-scale merged 2 commits into
mainfrom
annotate-init-subclass
Oct 12, 2026
Merged

earakely-scale merged 2 commits into
mainfrom
annotate-init-subclass

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Every __init_subclass__ hook in agent_env is now fully annotated, so a downstream package that type-checks strictly can subclass agent_env's classes again.

Why

agent_env ships py.typed, so a consumer's type checker checks its subclasses of agent_env's classes, and defining a subclass calls the base's __init_subclass__. Under mypy --strict (disallow_untyped_calls), calling a function with no annotations from typed code is an error, so every subclass of SandboxProvider has failed with Call to untyped function "__init_subclass__" in typed context [no-untyped-call] since 0.9.1312 (#159) added that hook. Universe's hook has the same problem.

What

  • SandboxProvider.__init_subclass__ and Universe.__init_subclass__ are now (cls, **kwargs: Any) -> None. TaskStep's already annotated its return, and gets **kwargs: Any for the same shape.
  • A unit test walks src/agent_env and fails on any __init_subclass__ that leaves a parameter or the return unannotated, since a subclass can't avoid calling one.

Tests

Unit tier: 7,415 passed. A strict-mypy downstream package that subclasses ModalSandboxProvider fails with the error above on 0.9.1313 and type-checks clean on this branch.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous test issue is fixed and no new actionable issues remain.

Summary

Adds type annotations to __init_subclass__ hooks so strict type checkers accept downstream subclasses.

  • Strict type checkers can follow agent_env subclass hooks.

Reviews (2) · Last reviewed commit: "test(typing): the hook test skips cls wh..." · Reviewed by Greptile

…checkers refuse to call untyped

agent_env ships py.typed, so a downstream package's type checker checks its subclasses of agent_env's
classes, and defining a subclass calls the base's __init_subclass__. SandboxProvider's (new in 0.9.1312)
and Universe's had no annotations, so under mypy --strict every subclass of them fails with
no-untyped-call; TaskStep's left **kwargs unannotated. All three are now
`__init_subclass__(cls, **kwargs: Any) -> None`, and a unit test keeps every such hook annotated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread tst/unit/test_subclass_hooks_are_annotated.py Outdated
…only

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 56b213e into main Oct 12, 2026
13 checks passed
@earakely-scale
earakely-scale deleted the annotate-init-subclass branch October 12, 2026 02:37
Sign up for free to 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.

1 participant