Skip to content

Raise TypeError for unknown keyword arguments to sprites - #2954

Merged
pvcraven merged 1 commit into
developmentfrom
sprite-reject-unknown-kwargs
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
sprite-reject-unknown-kwargs

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Sprites now raise TypeError for 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" to Sprite. #2953 removes that argument.

Before

  • Sprite and BasicSprite took **kwargs and ignored anything they didn't recognize.
  • SpriteSolidColor, SpriteCircle, TextureAnimationSprite and AnimatedWalkingSprite took **kwargs and dropped them entirely, so even valid Sprite arguments like angle were ignored.

A misspelled or outdated argument did nothing, with no error.

After

  • Sprite and BasicSprite accept only their named parameters. Sprite gains a named visible, the one extra parameter BasicSprite takes. Python now raises:

    TypeError: Sprite.__init__() got an unexpected keyword argument 'hit_box_algorithm'
    
  • The four subclasses pass extra keyword arguments on to Sprite. Unknown ones raise, and valid ones such as angle and visible now work: SpriteCircle(5, RED, angle=30).angle is 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, across arcade, doc and tests. I also ran every example.

  • Tilemap image layers passed filename and hit_box_algorithm to the sprite. The texture is already loaded with that hit box algorithm, so both are removed.
  • Animated tiles passed path_or_texture to TextureAnimationSprite, 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.
  • Platform tutorial steps 19 and 20 created bullets with scaling=0.8 instead of scale=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.
  • The card game tutorial: 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:

  • Each of the six classes raises for an unknown argument, including from a subclass's super().__init__.
  • visible works.
  • The four subclasses pass angle and visible on.

8 of the 9 fail on development. The tilemap image layer tests cover the tilemap change.

Checks

  • Full suite: 1797 passed. The only failures are the 11 card game tutorials that Drop the ignored hit_box_algorithm="None" from the card game tutorial #2953 fixes.
  • Examples: all 197 ran in a hidden window. 195 run; the other two can't run in my test harness: numpy_sprite needs numpy, and net_process_animal_facts uses multiprocessing, which can't pickle a class from a module run through runpy.
  • Code checks: ruff, mypy and pyright pass.

The changelog entry is under Unreleased → Breaking Changes.

🤖 Generated with Claude Code

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
pvcraven force-pushed the sprite-reject-unknown-kwargs branch from 48f0ba0 to b4583e6 Compare October 8, 2026 18:50
@pvcraven
pvcraven merged commit a182105 into development Oct 8, 2026
6 of 7 checks passed
@pvcraven
pvcraven deleted the sprite-reject-unknown-kwargs branch October 8, 2026 18:56
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