[PATCH 2 of 2 V3] py3: use namedtuple._replace to produce new tokens

Martijn Pieters mj at zopatista.com
Sun Oct 16 17:05:38 EDT 2016


On 16 Oct 2016, at 15:30, Pierre-Yves David <pierre-yves.david at ens-lyon.org> wrote:
> 
>> py3: use namedtuple._replace to produce new tokens
> 
> We seems to be using a private function of some stdlib type?
> Can you elaborate on why this is a good move?

It is not private. This is one of the exceptions to the Python style guide; the namedtuple methods all have a single leading underscore to avoid clashing with the field names. If they didn't, you wouldn't be able to name a field `replace`.

See the https://docs.python.org/3/library/collections.html#collections.namedtuple documentation:

> In addition to the methods inherited from tuples, named tuples support three additional methods and two attributes. To prevent conflicts with field names, the method and attribute names start with an underscore.

and https://docs.python.org/3/library/collections.html#collections.somenamedtuple._replace for the specific method:

> Return a new instance of the named tuple replacing specified fields with new values

--
Martijn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20161016/a091e0f3/attachment.sig>


More information about the Mercurial-devel mailing list