Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Use of __getattr__ in QuerySet #14

Open
Mec-iS opened this issue Feb 19, 2016 · 2 comments
Open

Use of __getattr__ in QuerySet #14

Mec-iS opened this issue Feb 19, 2016 · 2 comments

Comments

@Mec-iS
Copy link
Contributor

Mec-iS commented Feb 19, 2016

From a Python3 perspective, is it not wrong to use __getattr__ here instead of __getattribute__? Is there any design decision involved?

@agateblue
Copy link
Owner

The fact is I was not aware of the existence of __getattribute__. As the difference seems to be __getattr__ is called when no attribute was found, while __getattribute__ is always called (both and Python2 and Python3), I think that __getattr__ is the correct method to call here: we first check on the manager itself, then we proxy to the queryset. However, I'm possibly missing something here.

Still from that perspective, however, the try block is superfluous: if __getattr__ is called, it means no attribute has been found on the manager itself.

@Mec-iS
Copy link
Contributor Author

Mec-iS commented Feb 22, 2016

Then, I think the proper way of doing it is:

return getattr(super(Manager, self), attr)

because is the standard way of accessing an attribute in an object. getattr actually implement the Python mechanism for attributes' retrieval that involves also __getattr__ and __getattribute__ use.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants