I have a version of PyCXX ported to python 3.0 rc1 and its passing its tests. I'm porting pysvn to python 3.0 rc1 and hit an odd problem. Given this dict: wc_status_kind_map = { pysvn.wc_status_kind.added: 'A', pysvn.wc_status_kind.replaced: 'R', pysvn.wc_status_kind.unversioned: '?', } This fails: wc_status_kind_map[ pysvn.wc_status_kind.unversioned ] With: KeyError: <wc_status_kind.unversioned> Clearly I have a bug in the implementation of pysvn.wc_status_kind and could do with some suggestions on what to check please. I've assumed that if my objects support tp_hash and tp_compare they can be used as keys to a dictionary. My test scripts shows hash() and cmp() working. Why does "key in wc_status_kind_wc" work when I use an object returned by keys() by not when I use pysvn.wc_status_kind.unversioned? Barry --------- a.py -------- import pysvn wc_status_kind_map = { pysvn.wc_status_kind.replaced: 'R', pysvn.wc_status_kind.unversioned: 'U', } print( 'hash wc_status_kind', hash( "wc_status_kind" ) ) print( 'hash replace', hash( pysvn.wc_status_kind.replaced ) ) print( 'hash unversioned', hash( pysvn.wc_status_kind.unversioned ) ) print( 'cmp unversioned, unversioned', cmp ( pysvn.wc_status_kind.unversioned, pysvn.wc_status_kind.unversioned ) ) print( 'cmp unversioned, replaced', cmp ( pysvn.wc_status_kind.unversioned, pysvn.wc_status_kind.replaced ) ) print( 'cmp replaced, unversioned', cmp ( pysvn.wc_status_kind.replaced, pysvn.wc_status_kind.unversioned ) ) for key in wc_status_kind_map.keys(): print( '1 key', key, key in wc_status_kind_map, cmp( key, pysvn.wc_status_kind.unversioned ), hash( key ) ) try: print( '1 lookup', wc_status_kind_map[ key ] ) except: print( '1 failed' ) for key in [pysvn.wc_status_kind.added, pysvn.wc_status_kind.replaced, pysvn.wc_status_kind.unversioned]: print( '2 key', key, key in wc_status_kind_map, cmp( key, pysvn.wc_status_kind.unversioned ), hash( key ) ) try: print( '2 lookup', wc_status_kind_map[ key ] ) except: print( '2 failed' ) print( wc_status_kind_map[ pysvn.wc_status_kind.unversioned ] ) ------------ Output ------- $ python3.0 a.py hash wc_status_kind -586300918 hash replace -586300911 hash unversioned -586300916 cmp unversioned, unversioned 0 cmp unversioned, replaced -1 cmp replaced, unversioned 1 1 key replaced True 1 -586300911 1 lookup R 1 key unversioned True 0 -586300916 1 lookup U 2 key added False 1 -586300914 2 failed 2 key replaced False 1 -586300911 2 failed 2 key unversioned False 0 -586300916 2 failed Traceback (most recent call last): File "a.py", line 32, in <module> print( wc_status_kind_map[ pysvn.wc_status_kind.unversioned ] ) KeyError: <wc_status_kind.unversioned>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4