Repository navigation
fix(typing): annotate the __init_subclass__ hooks, which strict type checkers refuse to call untyped - #168
Merged
Conversation
…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>
…only Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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__. Undermypy --strict(disallow_untyped_calls), calling a function with no annotations from typed code is an error, so every subclass ofSandboxProviderhas failed withCall 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__andUniverse.__init_subclass__are now(cls, **kwargs: Any) -> None.TaskStep's already annotated its return, and gets**kwargs: Anyfor the same shape.src/agent_envand 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
ModalSandboxProviderfails with the error above on 0.9.1313 and type-checks clean on this branch.🤖 Generated with Claude Code


Confidence 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.agent_envsubclass hooks.Reviews (2) · Last reviewed commit: "test(typing): the hook test skips cls wh..." · Reviewed by Greptile