User-Agent: Mozilla/5.0 (X11; U; Linux i686; tr; rv:1.8.0.6) Gecko/20060808 Firefox/1.5.0.6 Build Identifier: Here is a small improvement in portage_util.py in function varexpand() which starts on line 288 ( my portage version is 2.1.2_pre2 btw ) : """ def varexpand(mystring,mydict={}): try: return cexpand[" "+mystring] except KeyError: pass """ This can be replaced with: def varexpand(mystring,mydict={}): if " "+mystring in cexpand.keys(): return cexpand[" "+mystring] ... which is more efficient than a try,except block Reproducible: Always
(In reply to comment #0) > This can be replaced with: > > def varexpand(mystring,mydict={}): > if " "+mystring in cexpand.keys(): > return cexpand[" "+mystring] > ... > which is more efficient than a try,except block Thanks. You know, that dict.keys() call is unnecessary. ;)
This is fixed in svn r4574. Here's what I did: newstring = cexpand.get(" "+mystring, None) if newstring is not None: return newstring
(In reply to comment #1) > (In reply to comment #0) > > This can be replaced with: > > > > def varexpand(mystring,mydict={}): > > if " "+mystring in cexpand.keys(): > > return cexpand[" "+mystring] > > ... > > which is more efficient than a try,except block > > Thanks. You know, that dict.keys() call is unnecessary. ;) > Yeah right :-) python is just being too clever sometimes..
This has been released in 2.1.2_pre2-r2.