[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Compatitbility broken in Rect.collidedict



Hello,

It appears that the Rect.collidedict method has had quite a bit of
overhaul between pygame 1.7 and pygame 1.8.

Documentation for pygame 1.7
> Rect.collidedict(dict if rectstyle keys) -> key/value pair find
> overlapping rectangle in a dictionary
> 
> Returns the key/value pair of the first rectangle key in the dict that
> overlaps the base rectangle. Once an overlap is found, this will stop
> checking the remaining list. If no overlap is found, it will return
> None.
> 
> Remember python dictionary keys must be immutable, Rects are not
> immutable, so they cannot directly be, dictionary keys. You can
> convert the Rect to a tuple with the tuple() builtin command.

Documentation for pygame 1.8
http://www.pygame.org/docs/ref/rect.html#Rect.collidedict

> Returns the key and value of the first dictionary value that collides
> with the Rect. If no collisions are found, None is returned. 
> 
> Rect objects are not hashable and cannot be used as keys in a
> dictionary, only as values. 

Both forms are actually quite useful for a number of different tasks.
Maybe you should have a 

Rect.collidedictkeys   <- Check against keys
Rect.collidedictvalues <- Check against values

and then map Rect.collidedict to the keys variety for backwards
compatibility?
 
Tim Ansell
---
http://blog.mithis.net/ - Mithro Rants about Stuff
http://www.thousandparsec.net/ - Conquer the Universe (and then some)