<div dir="ltr"><div>Well, for me having to check both __get__ and __str__ for a data descriptor feels inelegant.</div><div><br></div><div>After read the documentation of collections.abc again "This module provides abstract base classes that can be used to test whether a class provides a particular interface; for example, whether it is hashable or whether it is a mapping." I ask: what is the criteria to decide which interfaces are worth implemented as an ABC in the standard library?<br></div><div><br></div><div>To my understanding, any well defined python protocol should have a proper ABC.</div></div><br><div class="gmail_quote"><div dir="ltr">El mar., 17 ene. 2017 a las 18:55, Guido van Rossum (<<a href="mailto:guido@python.org">guido@python.org</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">For this use case I see nothing wrong with hasattr(myobj, '__set__').<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Tue, Jan 17, 2017 at 9:41 AM, Roberto Martínez <span dir="ltr" class="gmail_msg"><<a href="mailto:robertomartinezp@gmail.com" class="gmail_msg" target="_blank">robertomartinezp@gmail.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">I need to check if some objects obey the descriptor protocol in the construction of a metaclass. I expect to be able to write something like:<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">if isinstance(myobj, abc.DataDescriptor):</div><div class="gmail_msg"> # do something</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The other idea crossing my mind is something like:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">if all(hasattr(myobj, attr) for attr in ('__get__', '__set__')):</div><div class="gmail_msg"> # do something</div><div class="gmail_msg"><br class="gmail_msg"></div></div><div class="m_6838915142271029480HOEnZb gmail_msg"><div class="m_6838915142271029480h5 gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">El mar., 17 ene. 2017 a las 18:07, Guido van Rossum (<<a href="mailto:guido@python.org" class="gmail_msg" target="_blank">guido@python.org</a>>) escribió:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">Well, these are an example of the purest duck typing. Just implement __get__ and/or __set__ (and __delete__) and you're good.<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div>What's the situation where you miss them?<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div>--Guido<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div><div class="gmail_extra m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div></div><div class="gmail_extra m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">On Tue, Jan 17, 2017 at 8:51 AM, Roberto Martínez <span dir="ltr" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><<a href="mailto:robertomartinezp@gmail.com" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" target="_blank">robertomartinezp@gmail.com</a>></span> wrote:<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div></div><div class="gmail_extra m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><blockquote class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">Hi,<div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">I miss abstract base classes in collections.abc implementing the descriptor protocol. Any reason why they do not exist?</div><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">What do you think of adding NonDataDescriptor and DataDescriptor ABCs?</div><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></div><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">Best regards, </div><span class="m_6838915142271029480m_-3015198250169984551m_-596420847124627840HOEnZb m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><font class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" color="#888888"><div class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">Roberto</div></font></span></div>
<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></blockquote></div></div><div class="gmail_extra m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><blockquote class="gmail_quote m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">
Python-Dev mailing list<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">
<a href="mailto:Python-Dev@python.org" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" target="_blank">Python-Dev@python.org</a><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">
<br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"></blockquote></div></div><div class="gmail_extra m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" clear="all"><br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg">-- <br class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg"><div class="m_6838915142271029480m_-3015198250169984551m_-596420847124627840gmail_signature m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" class="m_6838915142271029480m_-3015198250169984551gmail_msg gmail_msg" target="_blank">python.org/~guido</a>)</div>
</div></blockquote></div>
</div></div></blockquote></div><br class="gmail_msg"><br clear="all" class="gmail_msg"><br class="gmail_msg">-- <br class="gmail_msg"><div class="m_6838915142271029480gmail_signature gmail_msg" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" class="gmail_msg" target="_blank">python.org/~guido</a>)</div>
</div>
</blockquote></div>