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

Martijn Pieters mj at zopatista.com
Tue Oct 11 13:19:23 EDT 2016


On 11 October 2016 at 17:50, Pierre-Yves David <
pierre-yves.david at ens-lyon.org> wrote:

>  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 ?
>

This fixes open(filename, 'r'), open(filename, 'w'), etc. calls. In Python
3, that second argument *must* be a string, you can't use bytes.

The fix is the same as used with getattr() (where the second argument must
also always be a string); in the tokenizer, where we detect calls, if there
is something that looks like a call to open (and is not an attribute, so
the previous token is not a "." dot) then make sure that that second
argument is not converted to a `bytes` object instead.

You can compare this to the "if fn in ('getattr', 'setattr', 'hasattr',
'safehasattr'):" block above this change.

-- 
Martijn Pieters
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20161011/33f5c236/attachment.html>


More information about the Mercurial-devel mailing list