[PATCH V2] py3: a second argument to open can't be bytes

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Oct 11 12:50:32 EDT 2016



On 10/09/2016 06:14 PM, Augie Fackler wrote:
> On Sun, Oct 09, 2016 at 02:10:40PM +0200, Martijn Pieters wrote:
>> # HG changeset patch
>> # User Martijn Pieters <mjpieters at fb.com>
>> # Date 1476015001 -7200
>> #      Sun Oct 09 14:10:01 2016 +0200
>> # Node ID 82489cd912f332be976cf432673ad47af0d04cd7
>> # Parent  a56076f85aa6aa728457ecc571ff58514bc59896
>> py3: a second argument to open can't be bytes
>
> Queued, thanks!

  I'm trying to double review this (to have it move from hg-commited to 
public phase) and this is a bit too obscure for me (I assume there was 
much more context around the py3 table). Martijn can you give me a bit 
more context about what it going on here? What problem are we fixing and 
how is this the right way to do it ?

>> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
>> --- a/mercurial/__init__.py
>> +++ b/mercurial/__init__.py
>> @@ -305,6 +305,24 @@
>>                      except IndexError:
>>                          pass
>>
>> +                # Bare open call (not an attribute on something else)
>> +                if (fn == 'open' and not (prevtoken.type == token.OP and
>> +                                          prevtoken.string == '.')):
>> +                    try:
>> +                        # (NAME, 'open')
>> +                        # (OP, '(')
>> +                        # (NAME|STRING, 'filename')
>> +                        # (OP, ',')
>> +                        # (NAME|STRING, mode)
>> +                        st = tokens[i + 4]
>> +                        if (st.type == token.STRING and
>> +                                st.string[0] in ("'", '"')):
>> +                            rt = tokenize.TokenInfo(st.type, 'u%s' % st.string,
>> +                                                    st.start, st.end, st.line)
>> +                            tokens[i + 4] = rt
>> +                    except IndexError:
>> +                        pass
>> +
>>                  # It changes iteritems to items as iteritems is not
>>                  # present in Python 3 world.
>>                  if fn == 'iteritems':
>> @@ -319,7 +337,7 @@
>>      # ``replacetoken`` or any mechanism that changes semantics of module
>>      # loading is changed. Otherwise cached bytecode may get loaded without
>>      # the new transformation mechanisms applied.
>> -    BYTECODEHEADER = b'HG\x00\x04'
>> +    BYTECODEHEADER = b'HG\x00\x05'
>>
>>      class hgloader(importlib.machinery.SourceFileLoader):
>>          """Custom module loader that transforms source code.
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list