Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active August 29, 2015 14:22
Show Gist options
  • Save kezabelle/0ef387611ecaa4bb9b87 to your computer and use it in GitHub Desktop.
Save kezabelle/0ef387611ecaa4bb9b87 to your computer and use it in GitHub Desktop.
... Why can't I see `__get_dynamic_attr` on a Django Feed?!
class A(object):
def b(self): return True
def _c(self): return True
def __d(self): return True
dir(A())
# ['_A__d', ..., '_c', 'b']
import django
django.VERSION
# (1, 8, 2, 'final', 0)
from django.contrib.syndication.views import Feed
class TestFeed(Feed):
# seems like it ought to fill the contract ...
# https://docs.djangoproject.com/en/1.8/ref/contrib/syndication/#a-simple-example
def items(self):
return ['a', 'b']
# emulates the binding made in a urlconf (ie: __init__ a single instance)
TestFeed()
# <__main__.TestFeed object at 0x101d96690>
# get_object defaults to None, so `obj` would be None ...
# __call__ does this internally inside get_feed ...
TestFeed().__get_dynamic_attr('link', None)
# AttributeError: 'TestFeed' object has no attribute '__get_dynamic_attr'
# wtf how is that not visible?
@kezabelle
Copy link
Author

See the double underscores before a name part of this URL. It's pretty hard to google for, because of the prevalence of magic methods. And here's the python docs on it ... I thought we were all adults and didn't need protected/private. Hmmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment