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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@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
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