Skip to content

Commit

Permalink
Merge pull request #72 from CTPUG/bugs/issue-60-unpack-rect
Browse files Browse the repository at this point in the history
Support arbitary numeric types for creating pygame surfaces
  • Loading branch information
drnlm committed Oct 9, 2016
2 parents 1bca558 + a40a925 commit 5575116
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 5575116

Please sign in to comment.