Skip to content

Commit

Permalink
Support arbitary numeric types for creating pygame surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil committed Oct 9, 2016
1 parent ce6bb6d commit a40a925
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pygame/_error.py
Expand Up @@ -2,6 +2,7 @@
"""

from pygame._sdl import sdl, ffi
from numbers import Number


class SDLError(Exception):
Expand All @@ -14,13 +15,18 @@ def from_sdl_error(cls):

def unpack_rect(rect):
"""Unpack the size and raise a type error if needed."""
# This is as liberal as pygame when used for pygame.surface, but
# more liberal for pygame.display. I don't think the inconsistency
# matters
if (not hasattr(rect, '__iter__') or
len(rect) != 2 or
not isinstance(rect[0], int) or
not isinstance(rect[1], int)):
not isinstance(rect[0], Number) or
not isinstance(rect[1], Number)):
raise TypeError("expected tuple of two integers but got %r"
% type(rect))
return rect
# We'll throw a conversion TypeError here if someone is using a
# complex number, but so does pygame.
return int(rect[0]), int(rect[1])


def get_error():
Expand Down

0 comments on commit a40a925

Please sign in to comment.