A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20140609/ddaa2075/attachment.html below:

<p dir="ltr"><br>
On 9 Jun 2014 10:04, "Raymond Hettinger" <<a href="mailto:raymond.hettinger@gmail.com">raymond.hettinger@gmail.com</a>> wrote:<br>
><br>
><br>
> On Jun 7, 2014, at 6:25 AM, R. David Murray <<a href="mailto:rdmurray@bitdance.com">rdmurray@bitdance.com</a>> wrote:<br>
><br>
>>> I guess I could duck-type it based on the _fields attribute but that <br>
>>> feels implicit and fragile.<br>
>>><br>
>>> What do you guys suggest?<br>
>><br>
>><br>
>> I seem to remember a previous discussion that concluded that duck typing<br>
>> based on _fields was the way to go. Â (It's a public API, despite the _,<br>
>> due to name-tuple's attribute namespacing issues.)<br>
><br>
><br>
> Yes. Â That is the recommended approach.<br>
><br>
> IIRC that was Guido's suggestion rather than creating an abstract<br>
> base class for a named tuple (any tuple-like class with indexable<br>
> elements that are also accessible using named attributes).</p>
<p dir="ltr">Given the somewhat periodic recurrence of the question, might it be worth making an ABC after all, with "subclass of tuple with a _fields attribute" as its default check?</p>
<p dir="ltr">"isinstance(obj, collections.NamedTupleABC)" is quite a bit more self-documenting than "isinstance(obj, tuple) and hasattr(obj, '_fields')"</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
><br>
> Raymond<br>
><br>
><br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
><br>
</p>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4