-
-
Notifications
You must be signed in to change notification settings - Fork 723
Description
Opened on behalf of @python-discord/devops
Problem
Earlier today I received notice from my Vice-Best Man @ChrisLovering that we were misinforming users who were using the !eval
command functionality of this project.
Chris rightly pointed out that the !eval
command behavior is actually really !exec
- we spawn a new Python process to execute the user's code, going far beyond the capabilities of the plain old eval()
built-in.
Current Behavior
The !eval
command currently:
- Sends user input to snekbox
- Spawns a new Python subprocess
- Executes arbitrary Python code (statements, not just expressions)
- Supports multi-line code blocks
- Allows imports, variable assignments, control flow, etc.
- Captures and returns stdout/stderr
This is fundamentally different from Python's eval()
function, which:
- Only evaluates single expressions
- Cannot execute statements like assignments or imports
- Runs in the current process context
- Is limited to expression evaluation
Proposed Solution
Add an !exec
alias that provides the same functionality as !eval
.
Benefits
- Accuracy: The command name reflects what it actually does
- User Education: Helps users understand the difference between
eval()
andexec()
- Clarity: New users won't be confused about the scope of execution
- Best Practices: Aligns with Python terminology and conventions
Implementation Notes
- The alias should be a simple addition that maps
!exec
to the existing!eval
functionality - No breaking changes to existing
!eval
usage - Both commands should have identical behavior.
- Help text should be updated to mention both aliases
Acceptance Criteria
-
!exec
command works identically to!eval
- No regression in existing
!eval
functionality - Consider adding a gentle notice about exec behaviour.
Additional Context
This change would help align our tool's terminology with standard Python concepts and reduce confusion for users learning about the differences between eval()
and exec()
in Python.