[PATCH 1 of 4] mail: let headencode() return a native string

Augie Fackler raf at durin42.com
Mon Nov 11 10:55:03 EST 2019



> On Nov 10, 2019, at 03:19, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> On Sat, 09 Nov 2019 17:06:40 +0100, Denis Laxalde wrote:
>> # HG changeset patch
>> # User Denis Laxalde <denis at laxalde.org>
>> # Date 1573299914 -3600
>> #      Sat Nov 09 12:45:14 2019 +0100
>> # Node ID 1c7a66bf3315f69036420e2b07b584abacfef881
>> # Parent  a78a65c33b5aa84cc9c3ae5f7dad636d371f149c
>> mail: let headencode() return a native string
> 
> Queued the first two, thanks.
> 
>> diff --git a/mercurial/mail.py b/mercurial/mail.py
>> --- a/mercurial/mail.py
>> +++ b/mercurial/mail.py
>> @@ -365,13 +365,13 @@ def headencode(ui, s, charsets=None, dis
>>     if not display:
>>         # split into words?
>>         s, cs = _encode(ui, s, charsets)
>> -        return encoding.strtolocal(email.header.Header(s, cs).encode())
>> -    return s
>> +        return email.header.Header(s, cs).encode()
>> +    return encoding.strfromlocal(s)
> 
> I think we should add some type comments to help readers to see which string
> type is returned/accepted/used. Mixing bytes and unicode is a nightmare.
> 
> I'm not an expert, but maybe we can annotate both functions and variables
> with "# type: <type expr>" comment?
> 
> https://google.github.io/pytype/user_guide.html#variable-annotations
> 
> Augie, do you have any idea?

Yes, you should be able to annotate individual variables like that. I've never actually annotated a variable, as typically I get plenty out of annotating functions, but it's definitely worth a shot where it's messy.


More information about the Mercurial-devel mailing list