sebpiq/django-rest-framework — comment on commit ca96b4523b4c09489e4bfe726a894a5c6ada78aa
File: djangorestframework/mixins.py line 103
By flashingpumpkin:

Also it would make sense to *not* have any assignment to private attributes in the `get_renderers` method. There is no indication that other methods rely on `self._renderers` to be set and that this has to happen in `get_renderers`. It's a bit counter intuitive.

I'd rather have this method *only* return / yield a list of renderers. Another private method can then take care of assigning the renderers to the private attribute.

I've also now seen that further below you rely on index based lookups for eg the default renderer. Yielding won't happen then.

Anyway.

I suggest:

```python
def get_renderers(self):
return [cls(self) for cls in self.renderers]

def _get_renderers(self):
if not hasattr(self, '_renderers'):
self._renderers = self.get_renderers()
return self._renderers
```

And all private methods in the mixin to call `_get_renderers`