[Python-Dev] collections.abc for data and non-data descriptors
Roberto Martínez
robertomartinezp at gmail.com
Tue Jan 17 14:41:24 EST 2017
Oh, I understand. Maybe is not worth the effort anyway.
Thank you
El mar., 17 ene. 2017 a las 19:40, Guido van Rossum (<guido at python.org>)
escribió:
But you can never get people to use the new ABCs consistently.
Anyway, I'm not -1, I'm just -0 -- I don't think it'll make any difference
and you're better off just checking for __set__ (if it only has __set__ but
not __get__, do you care what it is?).
On Tue, Jan 17, 2017 at 10:18 AM, Roberto Martínez <
robertomartinezp at gmail.com> wrote:
Well, for me having to check both __get__ and __str__ for a data descriptor
feels inelegant.
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?
To my understanding, any well defined python protocol should have a proper
ABC.
El mar., 17 ene. 2017 a las 18:55, Guido van Rossum (<guido at python.org>)
escribió:
For this use case I see nothing wrong with hasattr(myobj, '__set__').
On Tue, Jan 17, 2017 at 9:41 AM, Roberto Martínez <
robertomartinezp at gmail.com> wrote:
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:
if isinstance(myobj, abc.DataDescriptor):
# do something
The other idea crossing my mind is something like:
if all(hasattr(myobj, attr) for attr in ('__get__', '__set__')):
# do something
El mar., 17 ene. 2017 a las 18:07, Guido van Rossum (<guido at python.org>)
escribió:
Well, these are an example of the purest duck typing. Just implement
__get__ and/or __set__ (and __delete__) and you're good.
What's the situation where you miss them?
--Guido
On Tue, Jan 17, 2017 at 8:51 AM, Roberto Martínez <
robertomartinezp at gmail.com> wrote:
Hi,
I miss abstract base classes in collections.abc implementing the descriptor
protocol. Any reason why they do not exist?
What do you think of adding NonDataDescriptor and DataDescriptor ABCs?
Best regards,
Roberto
_______________________________________________
Python-Dev mailing list
Python-Dev at python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/guido%40python.org
--
--Guido van Rossum (python.org/~guido)
--
--Guido van Rossum (python.org/~guido)
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170117/d8ecde7f/attachment.html>
More information about the Python-Dev
mailing list