Repository navigation
Raise TypeError for unknown keyword arguments to sprites - #2954
Merged
Merged
Conversation
Sprite and BasicSprite took **kwargs and ignored anything they didn't recognize, so a wrong or outdated argument silently did nothing. They now accept only their named parameters (Sprite gains visible, the one extra parameter BasicSprite takes), so Python raises TypeError. SpriteSolidColor, SpriteCircle, TextureAnimationSprite and AnimatedWalkingSprite took **kwargs and dropped them entirely; they now pass them on to Sprite, so unknown ones raise and valid ones such as angle and visible work. Arguments that had silently done nothing: - tilemap image layers passed filename and hit_box_algorithm (the texture is already loaded with that hit box algorithm) - animated tiles passed path_or_texture (the animation sets the texture) - platform tutorial steps 19 and 20 passed scaling instead of scale, so bullets were drawn at full size instead of 80% Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pvcraven
force-pushed
the
sprite-reject-unknown-kwargs
branch
from
October 8, 2026 18:50
48f0ba0 to
b4583e6
Compare
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.
Summary
Sprites now raise
TypeErrorfor keyword arguments they don't accept, instead of silently ignoring them.Merge #2953 first. Until then, this PR's CI fails on the 11 card game tutorial files, which pass
hit_box_algorithm="None"toSprite. #2953 removes that argument.Before
SpriteandBasicSpritetook**kwargsand ignored anything they didn't recognize.SpriteSolidColor,SpriteCircle,TextureAnimationSpriteandAnimatedWalkingSpritetook**kwargsand dropped them entirely, so even validSpritearguments likeanglewere ignored.A misspelled or outdated argument did nothing, with no error.
After
SpriteandBasicSpriteaccept only their named parameters.Spritegains a namedvisible, the one extra parameterBasicSpritetakes. Python now raises:The four subclasses pass extra keyword arguments on to
Sprite. Unknown ones raise, and valid ones such asangleandvisiblenow work:SpriteCircle(5, RED, angle=30).angleis 30, where it used to be 0. Their docstrings document**kwargs.Arguments that had silently done nothing
I found these with an AST scan of every keyword argument passed to these classes, and to
super().__init__in their subclasses, acrossarcade,docandtests. I also ran every example.filenameandhit_box_algorithmto the sprite. The texture is already loaded with that hit box algorithm, so both are removed.path_or_texturetoTextureAnimationSprite, which dropped it. Now that arguments are passed on, it would have loaded the image as an extra texture before the animation set the real one, so it's removed.scaling=0.8instead ofscale=0.8, so bullets were drawn at full size. They're now 80%, as intended. These steps aren't included in the docs by line number.hit_box_algorithm="None", fixed in Drop the ignored hit_box_algorithm="None" from the card game tutorial #2953.Tests
New
tests/unit/sprite/test_sprite_init_arguments.py:super().__init__.visibleworks.angleandvisibleon.8 of the 9 fail on development. The tilemap image layer tests cover the tilemap change.
Checks
numpy_spriteneeds numpy, andnet_process_animal_factsuses multiprocessing, which can't pickle a class from a module run throughrunpy.The changelog entry is under Unreleased → Breaking Changes.
🤖 Generated with Claude Code