a standard descriptor signature?

102 views
Skip to first unread message

Tim Graham

unread,
Oct 24, 2015, 6:36:32 PM10/24/15
to Django developers (Contributions to Django itself)
Curtis, or should I say FunkyBob, raised the issue here: https://github.com/django/django/pull/5226

Currently we have several different signatures:

def __get__(self, instance, instance_type=None)
def __get__(self, obj, type=None):
def __get__(self, instance, type=None)
def __get__(self, obj, objtype)
def __get__(self, instance, owner)

and the Python docs don't seem to have a single preference.

Curtis proposed:
"""
* "instance_type" is explicit
* "cls" is a common convention for passing a class
* "owner" is in the docs {but so are others}
* and "type" I think is a bit confusing...

So... my preference, upon reflection, would be: def __get__(self, instance, cls=None):
"""

For set, it's mostly: def __set__(self, instance, value)
but a couple times: def __set__(self, obj, value)

Do you think it's worth trying to be consistent or not?

charettes

unread,
Oct 25, 2015, 12:09:14 PM10/25/15
to Django developers (Contributions to Django itself)
Now that Curtis did all the investigation work I think it wouldn't hurt being consistent here.

__get__(self, instance, cls=None) and __set__(self, instance, value) look like sane defaults to me.

Loïc Bistuer

unread,
Oct 25, 2015, 11:25:25 PM10/25/15
to django-d...@googlegroups.com
+1
> --
> You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
> To post to this group, send email to django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/39cb93c3-a6e5-4deb-b34f-95bd844a764e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Marc Tamlyn

unread,
Oct 26, 2015, 8:22:21 AM10/26/15
to django-d...@googlegroups.com
Sounds good to me. There's not any (good) reason why anyone would be calling these with kwargs that I can think of so we're safe from a compat perspective.

Marc

Tim Graham

unread,
Oct 26, 2015, 3:51:47 PM10/26/15
to Django developers (Contributions to Django itself)
Reply all
Reply to author
Forward
0 new messages