Skip to content

Let setup code import server params - #47

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/server-data-module
Nov 18, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/server-data-module

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

For #5. Setup code can now import data["params"] instead of reading the injected __data_params and __from_server_json globals, which IDEs and linters flag as undefined:

from pytest_prairielearn_grader.server_data import from_server_json, params

np.random.seed(params["seed"])
A = from_server_json(params["A"])
  • The sandbox's importer gives setup code its own copy of the module, kept out of sys.modules, whatever the whitelist and blacklist say. import pytest_prairielearn_grader.server_data and from pytest_prairielearn_grader import server_data work too.
  • After setup code finishes, importing it raises ImportError, so student code still can't read the params.
  • The real module in the package only exists for type checkers. Reading params outside the sandbox, for example in a test, raises an error that points to the data_json fixture.
  • __data_params and __from_server_json still work, so existing questions don't change. The docs now use the import.

This doesn't add the issue's server_data.seed attribute access. IDEs can't check those names either way, and params["seed"] keeps a single way to read them. It would be a small module __getattr__ if we want it.

🤖 Generated with Claude Code

…erver_data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 18, 2026 08:00
@eliotwrobson
eliotwrobson merged commit 38326aa into main Nov 18, 2026
5 checks passed
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.

1 participant