[PATCH V2] py3: change explicit conversion from str to pycompat.bytestr

Martin von Zweigbergk martinvonz at google.com
Fri Mar 17 16:02:54 EDT 2017


On Fri, Mar 17, 2017 at 12:55 PM, Rishabh Madan <rishabhmadan96 at gmail.com>
wrote:

> Do you know how that works? Since it's not pycompat.bytestr, I don't
>> understand what makes it work. So if you add something like this at the end
>> of the "if fm.isplain():" block:
>>             if pycompat.ispy3:
>>                print 'value is bytestr', isinstance(value,
>> pycompat.bytestr)
>> it prints "value is bytestr: True"? Or is that actually false and it
>> somehow doesn't rely on the __iter__ or __getitem__ methods to work
>> correctly when fm.isplain()?
>
>
>  It does print true for isinstance(value, pycompat.bytestr).
>

Oh, so bytestr.replace() does return a bytestr. I guess I just
misunderstood Yuya then. Yuya, can you confirm?



> Although, I am not able to know if it relies on __iter__ / __getitem__
> method or not.
>
>
>>
> On Sat, Mar 18, 2017 at 12:12 AM, Martin von Zweigbergk <
> martinvonz at google.com> wrote:
>
>>
>>
>> On Fri, Mar 17, 2017 at 11:22 AM, Rishabh Madan <rishabhmadan96 at gmail.com
>> > wrote:
>>
>>> The replace() function for py3 wasn't working when `value` was being
>>> typecasted as str. When I used pycompat.bytestr the error was resolved.
>>> So I guess it is preserved by such methods.
>>>
>>
>> Do you know how that works? Since it's not pycompat.bytestr, I don't
>> understand what makes it work. So if you add something like this at the end
>> of the "if fm.isplain():" block:
>>
>>             if pycompat.ispy3:
>>                print 'value is bytestr', isinstance(value,
>> pycompat.bytestr)
>>
>> it prints "value is bytestr: True"? Or is that actually false and it
>> somehow doesn't rely on the __iter__ or __getitem__ methods to work
>> correctly when fm.isplain()?
>>
>>
>>>
>>>>>>
>>> On Fri, Mar 17, 2017 at 10:45 PM, Martin von Zweigbergk <
>>> martinvonz at google.com> wrote:
>>>
>>>>
>>>>
>>>> On Fri, Mar 17, 2017 at 6:49 AM, Rishabh Madan <
>>>> rishabhmadan96 at gmail.com> wrote:
>>>>
>>>>> Sorry. I didn't know that changing the changeset message for V2
>>>>> forwards it as a different stream.
>>>>>>>>>>
>>>>> On Fri, Mar 17, 2017 at 7:14 PM, Rishabh Madan <
>>>>> rishabhmadan96 at gmail.com> wrote:
>>>>>
>>>>>> # HG changeset patch
>>>>>> # User Rishabh Madan <rishabhmadan96 at gmail.com>
>>>>>> # Date 1489758142 -19800
>>>>>> #      Fri Mar 17 19:12:22 2017 +0530
>>>>>> # Node ID 3d6d9294e2247316541942c4bec5186cb5772cd6
>>>>>> # Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
>>>>>> py3: change explicit conversion from str to pycompat.bytestr
>>>>>>
>>>>>> diff -r a5bad127128d -r 3d6d9294e224 mercurial/commands.py
>>>>>> --- a/mercurial/commands.py     Wed Mar 15 15:48:57 2017 -0700
>>>>>> +++ b/mercurial/commands.py     Fri Mar 17 19:12:22 2017 +0530
>>>>>> @@ -1813,7 +1813,7 @@
>>>>>>      matched = False
>>>>>>      for section, name, value in ui.walkconfig(untrusted=untrusted):
>>>>>>          source = ui.configsource(section, name, untrusted)
>>>>>> -        value = str(value)
>>>>>> +        value = pycompat.bytestr(value)
>>>>>>          if fm.isplain():
>>>>>>              source = source or 'none'
>>>>>>              value = value.replace('\n', '\\n')
>>>>>>
>>>>>
>>>> I thought I read that pycompat.bytestr-ness is not preserved by
>>>> operations (such as replace() on this line). If that's correct, will the
>>>> above still work if fm.isplain()?
>>>>
>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Rishabh Madan
>>>>> Second Year Undergraduate student
>>>>> Indian Institute of Technology, Kharagpur
>>>>>
>>>>> _______________________________________________
>>>>> Mercurial-devel mailing list
>>>>> Mercurial-devel at mercurial-scm.org
>>>>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Rishabh Madan
>>> Second Year Undergraduate student
>>> Indian Institute of Technology, Kharagpur
>>>
>>> _______________________________________________
>>> Mercurial-devel mailing list
>>> Mercurial-devel at mercurial-scm.org
>>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>>>
>>>
>>
>
>
> --
> Rishabh Madan
> Second Year Undergraduate student
> Indian Institute of Technology, Kharagpur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170317/11db00a9/attachment.html>


More information about the Mercurial-devel mailing list