Deprecate Cache.has_key()?

263 views
Skip to first unread message

Tim Graham

unread,
Jan 29, 2016, 6:11:54 PM1/29/16
to Django developers (Contributions to Django itself)
Any opposition to deprecating Cache.has_key()? Cache already implements __contains__() so converting has_key() to "in" can be done with existing versions of Django. Anyone using flake8 will get a warning about has_key() usage: W601 .has_key() is deprecated, use 'in'.

Tim Graham

unread,
Jan 29, 2016, 6:42:12 PM1/29/16
to Django developers (Contributions to Django itself)
Also the template BaseContext class has an undocumented has_key() method. I wonder if that can be removed without a deprecation?

https://github.com/django/django/pull/6066

Curtis Maloney

unread,
Jan 29, 2016, 8:04:33 PM1/29/16
to django-d...@googlegroups.com, Tim Graham
Isn't this so it complies with the dict interface? True, it's discouraged now, but it's still there.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Tim Graham

unread,
Jan 30, 2016, 7:34:14 AM1/30/16
to Django developers (Contributions to Django itself)
Yes, but dict.has_key() is removed in Python 3. If we started the deprecation in Django now, it would be scheduled for removal in Django 2.0 which also drops support for Python 2.

Adam Johnson

unread,
Jan 31, 2016, 4:26:12 AM1/31/16
to Django developers (Contributions to Django itself)
Might be problematic for third-party cache backends which implement has_key and rely on __contains__ calling it - don't see how you can show the warning in that case.

Tim Graham

unread,
Feb 1, 2016, 1:25:29 PM2/1/16
to Django developers (Contributions to Django itself)
We have django.utils.deprecation.RenameMethodsBase to help with that, but now I see that subclasses have this signature, `def has_key(self, key, version=None)`, so it doesn't seem the method can be replaced with __contains__.

Proposal withdrawn.
Reply all
Reply to author
Forward
0 new messages