Skip to content

Allow common builtins such as sum and super by default - #40

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/more-default-builtins
Nov 11, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/more-default-builtins

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Student code only gets RestrictedPython's list of safe builtins, which leaves out many that correct solutions use. A solution like sum(values) / len(values) fails with NameError: name 'sum' is not defined unless the question sets builtin_whitelist, and so does any class that calls super().

This adds all, any, ascii, bin, bytearray, classmethod, Ellipsis, filter, format, frozenset, iter, next, NotImplemented, object, property, reversed, staticmethod, sum, super and type to the defaults. None of them gives student code anything it can't already do with plain syntax. Builtins that read or change namespaces and attributes by name (getattr, setattr, vars, globals and the like), plus open, eval, exec, compile and input, stay blocked.

The new test_default_builtins scenario fails without this change. test_helper_modules_workspace used sum as its example of a blocked builtin, so it uses vars now.

The docs in #38 describe the current defaults, and I'll update them to match this PR.

🤖 Generated with Claude Code

eliotwrobson added a commit that referenced this pull request Nov 11, 2026
Correct solutions that use sum, any, all, super and similar builtins failed with a NameError
unless the question whitelisted them. These builtins don't give student code anything that
plain Python syntax doesn't.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eliotwrobson
eliotwrobson force-pushed the claude/more-default-builtins branch from dc3e280 to 4ed4214 Compare November 11, 2026 06:05
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 11, 2026 06:06
@eliotwrobson
eliotwrobson merged commit 41e5c2d into main Nov 11, 2026
5 checks passed
eliotwrobson added a commit that referenced this pull request Nov 12, 2026
* Add a guide for converting questions from the legacy Python grader

Also document leading and trailing code, query_setup and the limits on
setup code in the quick start, and fix the module-level timeout example,
which used a variable the plugin doesn't read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Encourage moving leading, trailing and setup code into tests when converting

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Reorganize quick_start.md for new users and keep converting.md conversion-specific

quick_start.md now starts with a first question, local testing and where code belongs, then
the API reference. It fixes the list of default builtins and the examples that relied on
bare asserts. converting.md links to it instead of repeating general guidance, rewrites the
square example to avoid setup code, and calls out the restricted builtins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Recommend import_blacklist for blocking library functions

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Describe the default builtins from #40

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Remove the note that blocking functions needs a newer release

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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