Repository navigation
Use CPython 3.14's wording for interpreter error messages - #950
Merged
Merged
Conversation
pyscript raised its own wording for many errors that Python raises itself. Use CPython 3.14's messages instead: - unpacking: "not enough values to unpack (expected 3, got 2)", "too many values to unpack (expected 2, got 3)" (the count only for a list, tuple or dict, as in Python), and "cannot unpack non-iterable int object"; an exception other than TypeError from iter() is no longer replaced - calls: "missing 2 required positional arguments: 'a' and 'b'", "takes from 1 to 2 positional arguments but 3 were given" (including the keyword-only variant), "missing 1 required keyword-only argument: 'b'" and "got an unexpected keyword argument 'a'"; the missing count was also wrong when a later argument was passed by keyword - "'return' outside function", "'break' outside loop", "'continue' not properly in loop", "nonlocal declaration not allowed at module level" - "cannot access local variable 'x' where it is not associated with a value" (UnboundLocalError), "cannot access free variable 'x' where it is not associated with a value in enclosing scope", also for del, and "name 'x' is not defined" for a global Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pyscript raised its own wording for many errors that Python raises itself. Running
tests/test_unit_eval.py's expected exceptions under CPython 3.14 showed about 20 with the same exception type but different text. This switches them to CPython 3.14's messages.too few values to unpack (expected 3)not enough values to unpack (expected 3, got 2)too many values to unpack (expected 2)too many values to unpack (expected 2, got 3); the count is given only for a list, tuple or dict, as in Pythoncannot unpack non-iterable objectcannot unpack non-iterable int objectf() missing 1 required positional argumentsf() missing 2 required positional arguments: 'a' and 'b'f() missing required keyword-only argumentsf() missing 1 required keyword-only argument: 'b'f() called with too many positional argumentsf() takes from 1 to 2 positional arguments but 3 were given, including the(and 1 keyword-only argument)formf() called with unexpected keyword arguments: a, cf() got an unexpected keyword argument 'a', the first one in call orderreturn statement outside function,break/continue statement outside loop'return' outside function,'break' outside loop,'continue' not properly in loopnonlocal statement outside functionnonlocal declaration not allowed at module levellocal variable 'x' referenced before assignmentcannot access local variable 'x' where it is not associated with a valuename 'x' is not defined(an enclosing function's variable, read ordel)cannot access free variable 'x' where it is not associated with a value in enclosing scopeglobal name 'x' is not definedname 'x' is not definedTwo small fixes came along:
def f(a, b)called asf(b=2)saidmissing 2. It now names just'a'.TypeErrorraised while iterating the value being unpacked is no longer replaced by "cannot unpack non-iterable object".Not changed
C.m() missing .... Pyscript functions don't track a qualified name, so pyscript still saysm() missing ....global xat module level still raises aSyntaxError. Python allows it, so it has no message to match.task.*, import restrictions,@pyscript_compilearguments) are unchanged.Testing
del) matches everywhere except the method-name prefix.tests/test_unit_eval.py's expected exceptions no longer differ from CPython, apart from pyscript-only features.pytest(307 passed), ruff, pylint, mypy and pre-commit pass.#947 currently raises the old
UnboundLocalErrorwording; it should use the new message once this is merged.🤖 Generated with Claude Code