# HG changeset patch # User Renato Cunha # Date 2010-07-15 01:59:43 # Node ID 7546d4a272c8ab72d29c1b1f40f4b98fc43237c4 # Parent 9bbfeba33aa38ec30924af29928135881e05a455 util: improved the check for the existence of the 'buffer' builtin 2to3 is unable to translate '__builtin__' calls to 'builtins' when hasattr is used (as in hasattr(__builtin__, buffer)). Translating the check to the format try: whatever except NameError # define whatever __builtin__.whatever = whatever is a correct way of checking for the name and has the benefit of being translated by 2to3. This patch implements the same idea for the aforementioned example. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -40,7 +40,9 @@ import __builtin__ def fakebuffer(sliceable, offset=0): return sliceable[offset:] -if not hasattr(__builtin__, 'buffer'): +try: + buffer +except NameError: __builtin__.buffer = fakebuffer import subprocess