Skip to content

Complete type hinting across scienceworld package; add opt-in mypy tox env - #89

Open
pangwangshu wants to merge 1 commit into
allenai:mainfrom
pangwangshu:wapang/issue58
Open

Complete type hinting across scienceworld package; add opt-in mypy tox env#89
pangwangshu wants to merge 1 commit into
allenai:mainfrom
pangwangshu:wapang/issue58

Conversation

@pangwangshu

Copy link
Copy Markdown

Summary

Fixes #58.

Type hinting was already partially added to ScienceWorldEnv's snake_case API in earlier commits. This PR completes the coverage and, per MarcCote's comment on the issue, wires up an opt-in mypy check without making it mandatory.

  • Add type hints to scienceworld/utils.py (infer_task, snake_case_deprecation_warning), which had none.
  • Add type hints to the remaining untyped surface of scienceworld/scienceworld.py: the deprecated camelCase wrapper methods, __del__, getObjectTree, get_max_variations's parameter, and the whole BufferedHistorySaver class.
  • Fix two bugs surfaced by mypy while typing:
    • getRunHistorySize() called a nonexistent get_run_historySize() method (should be get_run_history_size()) — would have raised AttributeError for any camelCase-API caller.
    • ScienceWorldEnv.__init__'s taskName/serverPath params were implicitly Optional[str].
  • Add a [testenv:mypy] section to tox.ini, deliberately not part of the default envlist/CI matrix, so it's runnable via tox -e mypy without gating builds — matching the "not mandatory for now" ask in the issue thread.

Test plan

  • mypy scienceworld — no issues found
  • flake8 scienceworld --max-line-length 120 — clean
  • Relevant pre-commit checks (trailing-whitespace, end-of-file-fixer, codespell) — clean on changed files
  • All changed files parse/compile (py_compile)
  • Full pytest suite — not run locally (no JVM available in the sandbox this was developed in); relies on CI, which builds the Scala JAR

🤖 Generated with Claude Code

Extends the type hints already started on ScienceWorldEnv's snake_case
API to the remaining untyped surface: utils.py, the deprecated camelCase
wrapper methods, __del__, getObjectTree, and BufferedHistorySaver. Also
fixes two bugs uncovered by mypy: getRunHistorySize() called a
nonexistent get_run_historySize() method, and __init__'s taskName/
serverPath params were implicitly Optional.

Per MarcCote's comment on allenai#58, adds mypy as a testenv that is not part
of tox's default envlist, so it's available via `tox -e mypy` without
becoming a mandatory CI check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@pangwangshu pangwangshu mentioned this pull request Aug 5, 2026
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.

Type Hinting

1 participant