<div dir="ltr">For this use case I see nothing wrong with hasattr(myobj, '__set__').<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 17, 2017 at 9:41 AM, Roberto Martínez <span dir="ltr"><<a href="mailto:robertomartinezp@gmail.com" target="_blank">robertomartinezp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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><br></div><div>if isinstance(myobj, abc.DataDescriptor):</div><div> # do something</div><div><br></div><div>The other idea crossing my mind is something like:</div><div><br></div><div>if all(hasattr(myobj, attr) for attr in ('__get__', '__set__')):</div><div> # do something</div><div><br></div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">El mar., 17 ene. 2017 a las 18:07, Guido van Rossum (<<a href="mailto:guido@python.org" target="_blank">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="m_-3015198250169984551gmail_msg"><div class="m_-3015198250169984551gmail_msg"><div class="m_-3015198250169984551gmail_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_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"></div>What's the situation where you miss them?<br class="m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"></div>--Guido<br class="m_-3015198250169984551gmail_msg"></div><div class="gmail_extra m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"><div class="gmail_quote m_-3015198250169984551gmail_msg"></div></div><div class="gmail_extra m_-3015198250169984551gmail_msg"><div class="gmail_quote m_-3015198250169984551gmail_msg">On Tue, Jan 17, 2017 at 8:51 AM, Roberto Martínez <span dir="ltr" class="m_-3015198250169984551gmail_msg"><<a href="mailto:robertomartinezp@gmail.com" class="m_-3015198250169984551gmail_msg" target="_blank">robertomartinezp@gmail.com</a>></span> wrote:<br class="m_-3015198250169984551gmail_msg"></div></div><div class="gmail_extra m_-3015198250169984551gmail_msg"><div class="gmail_quote m_-3015198250169984551gmail_msg"><blockquote class="gmail_quote m_-3015198250169984551gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-3015198250169984551gmail_msg">Hi,<div class="m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"></div><div class="m_-3015198250169984551gmail_msg">I miss abstract base classes in collections.abc implementing the descriptor protocol. Any reason why they do not exist?</div><div class="m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"></div><div class="m_-3015198250169984551gmail_msg">What do you think of adding NonDataDescriptor and DataDescriptor ABCs?</div><div class="m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"></div><div class="m_-3015198250169984551gmail_msg">Best regards, </div><span class="m_-3015198250169984551m_-596420847124627840HOEnZb m_-3015198250169984551gmail_msg"><font class="m_-3015198250169984551gmail_msg" color="#888888"><div class="m_-3015198250169984551gmail_msg">Roberto</div></font></span></div>
<br class="m_-3015198250169984551gmail_msg"></blockquote></div></div><div class="gmail_extra m_-3015198250169984551gmail_msg"><div class="gmail_quote m_-3015198250169984551gmail_msg"><blockquote class="gmail_quote m_-3015198250169984551gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br class="m_-3015198250169984551gmail_msg">
Python-Dev mailing list<br class="m_-3015198250169984551gmail_msg">
<a href="mailto:Python-Dev@python.org" class="m_-3015198250169984551gmail_msg" target="_blank">Python-Dev@python.org</a><br class="m_-3015198250169984551gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" class="m_-3015198250169984551gmail_msg" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br class="m_-3015198250169984551gmail_msg">
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" class="m_-3015198250169984551gmail_msg" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br class="m_-3015198250169984551gmail_msg">
<br class="m_-3015198250169984551gmail_msg"></blockquote></div></div><div class="gmail_extra m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg"><br class="m_-3015198250169984551gmail_msg" clear="all"><br class="m_-3015198250169984551gmail_msg">-- <br class="m_-3015198250169984551gmail_msg"><div class="m_-3015198250169984551m_-596420847124627840gmail_signature m_-3015198250169984551gmail_msg" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" class="m_-3015198250169984551gmail_msg" target="_blank">python.org/~guido</a>)</div>
</div></blockquote></div>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>