Skip to content

refactor(python): modernize and fix typing in schola/core, 3.10 bug fixes#26

Open
noamonti748 wants to merge 12 commits into
mainfrom
noamonti748/core-typing
Open

refactor(python): modernize and fix typing in schola/core, 3.10 bug fixes#26
noamonti748 wants to merge 12 commits into
mainfrom
noamonti748/core-typing

Conversation

@noamonti748

Copy link
Copy Markdown
Collaborator

Summary

Improves static typing across the Schola Python core package (schola.core) using basedpyright, with targeted pyrightconfig.json execution environments so protobuf, protocol, simulator, and utility modules can be checked incrementally without drowning in generated-code noise.

Also fixes a real ONNX export bug (make_box_output parameter name mismatch) and documents Python version constraints for AsyncVecEnv (asyncio.TaskGroup requires 3.11+). Tests are updated for the new annotations and for Python 3.10 vs 3.11 behavior (xfail/skipif where Ray pickling or TaskGroup are incompatible).

Related issues

None.

Type of change

  • Bug fix
  • Refactor or internal cleanup

Changes

Static typing (basedpyright)

  • Expanded pyrightconfig.json with per-directory execution environments for:

    • schola/core/protocols/protobuf suppress unknown-type noise from generated protobuf bindings
    • schola/core/protocols, schola/core/simulators/unreal, schola/core/utils scoped rule overrides for incremental adoption
  • Annotated core modules with modern typing (X | None, built-in dict/list, typing_extensions.override, targeted # pyright: file pragmas where full strictness is impractical):

    • Protocols: base_protocol, async_base_protocol, socket_protocol, gRPC/protobuf stack (serialize, deserialize, grpc_protocol, async_grpc_protocol, offline_grpc_protocol)
    • Simulators: base_simulator, external_simulator, Unreal simulators (base, executable, project)
    • Utils: dict_helpers, id_manager, plugins, ubt
    • Model / errors: model.py, error_manager.py
  • Updated corresponding tests under Test/core/ for typing compliance (e.g. @override on stub protocol classes, assertion style changes).

Bug fixes uncovered during typing / test runs

  • rllib/export.py: ScholaRLModule and RllibScholaModel.make_box_output now accept _space_name (matching ScholaModel.make_fundamental_output), fixing torch.export / ONNX export failures (unexpected keyword argument '_space_name').
  • sb3/async_env.py: AsyncVecEnv.__init__ raises a clear RuntimeError on Python < 3.11 because it uses asyncio.TaskGroup.

Python 3.10 test handling

  • Test/sb3/test_async_env.py: module-level pytest.mark.xfail on Python < 3.11 (raises=RuntimeError) plus early pytest.xfail() in the shared fixture so setup does not ERROR.
  • Test/rllib/scripts/test_eval_cli.py: skipif on test_apply_env_config_rebuilds_real_eval_env_runner_group on Python < 3.11 (Ray eval-config pickling with MagicMock stubs fails on 3.10; passes on 3.11).

Testing

Python (Resources/python, Test)

  • Installed test dependencies: pip install --group test -e "./Resources/python[all]"
  • Ran: python -m pytest Test --import-mode=importlib -n 0

Unreal C++ (Source)

  • Not applicable

Checklist

  • Code follows project style (Unreal coding standard for C++; Black for Python)
  • Comments / docstrings added or updated where behavior is non-obvious
  • README or Sphinx docs updated if user-facing behavior changed
  • No unrelated changes included in this PR
  • Appropriate license headers added to new files

Monti, Noah and others added 2 commits June 25, 2026 11:32
@noamonti748 noamonti748 self-assigned this Jun 25, 2026
@noamonti748 noamonti748 added the refactor Restructures/improves existing code label Jun 25, 2026
@noamonti748 noamonti748 changed the title refactor(python): modernize and fix typing in schola/core refactor(python): modernize and fix typing in schola/core, 3.10 bug fixes Jun 25, 2026
@noamonti748 noamonti748 marked this pull request as ready for review June 30, 2026 17:24
Comment thread Resources/python/schola/core/protocols/protobuf/deserialize.py
Comment thread Resources/python/schola/core/protocols/protobuf/deserialize.py
Comment thread Resources/python/schola/core/protocols/protobuf/deserialize.py Outdated
Comment thread Resources/python/schola/core/error_manager.py Outdated
Comment thread Resources/python/schola/core/model.py
Comment thread Resources/python/schola/core/model.py Outdated
Comment thread Resources/python/schola/core/protocols/protobuf/grpc_protocol.py Outdated
):

self,
auto_reset_type: AutoResetType | AutoresetMode | int = AutoResetType.SAME_STEP,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it so that this function takes only AutoResetType. Caller(s) can be responsible for using the coerce helper to get an AutoResetType. That will prevent the temptation to expand the signature for the next framework with their own AutoReset Enum

Comment thread Resources/python/schola/core/protocols/protobuf/offline_grpc_protocol.py Outdated
Comment thread pyrightconfig.json
Comment thread Resources/python/schola/core/utils/dict_helpers.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructures/improves existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants