Guido van Rossum | 3bead09 | 1992-01-27 17:00:37 +0000 | [diff] [blame] | 1 | # Python test set -- part 3, built-in operations. |
| 2 | |
| 3 | |
| 4 | print '3. Operations' |
Fred Drake | 762c1cb | 2000-08-31 19:48:52 +0000 | [diff] [blame] | 5 | print 'XXX Mostly not yet implemented' |
| 6 | |
| 7 | |
| 8 | print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception' |
| 9 | |
| 10 | # SourceForge bug #112558: |
| 11 | # http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470 |
| 12 | |
| 13 | class BadDictKey: |
| 14 | def __hash__(self): |
| 15 | return hash(self.__class__) |
| 16 | |
| 17 | def __cmp__(self, other): |
| 18 | if isinstance(other, self.__class__): |
| 19 | print "raising error" |
| 20 | raise RuntimeError, "gotcha" |
| 21 | return other |
| 22 | |
| 23 | d = {} |
| 24 | x1 = BadDictKey() |
| 25 | x2 = BadDictKey() |
| 26 | d[x1] = 1 |
| 27 | d[x2] = 2 |
| 28 | print "No exception passed through." |