Skip to content

Add clearer 2D point validation for 2D drawing functions #2215

Description

@pushfoo

Enhancement request:

TL;DR: Add clearer exceptions on malformed visually Point2List cases like [(1,), (2, 2), (1,)]

What should be added/changed?

As of #2213, we annotate 2D line drawing functions with Point2List.

We should the following:

  1. A try / catch block or other validation to help detect bad data and report it nicely
  2. Tests if we return a ValueError since the current behavior returns a TypeError

What would it help with?

It would make the traceback clearer when malformed data is passed.

The traceback below is produced by this (example code):

Traceback (most recent call last):
  File "/home/user/src/arcade/.scratch/line_validation_reason.py", line 24, in <module>
    arcade.run()
  File "/home/user/src/arcade/arcade/window_commands.py", line 139, in run
    pyglet.app.run(window._draw_rate)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/app/__init__.py", line 80, in run
    event_loop.run(interval)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/app/base.py", line 165, in run
    timeout = self.idle()
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/app/base.py", line 226, in idle
    self.clock.call_scheduled_functions(dt)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/clock.py", line 217, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/app/base.py", line 120, in _redraw_windows
    window.dispatch_event('on_draw')
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/window/__init__.py", line 676, in dispatch_event
    super().dispatch_event(*args)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/event.py", line 394, in dispatch_event
    self._raise_dispatch_exception(event_type, args, getattr(self, event_type), exception)
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/event.py", line 446, in _raise_dispatch_exception
    raise exception
  File "/home/user/src/arcade/.venv/lib/python3.9/site-packages/pyglet/event.py", line 387, in dispatch_event
    if getattr(self, event_type)(*args):
  File "/home/user/src/arcade/.scratch/line_validation_reason.py", line 19, in on_draw
    arcade.draw_lines(self.malformed, arcade.color.RED, line_width=10)
  File "/home/user/src/arcade/arcade/draw/line.py", line 98, in draw_lines
    line_pos_array = array.array("f", (v for point in point_list for v in point))
  File "/home/user/src/arcade/arcade/draw/line.py", line 98, in <genexpr>
    line_pos_array = array.array("f", (v for point in point_list for v in point))
TypeError: 'int' object is not iterable

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions