Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 1.93 KB

README.md

File metadata and controls

21 lines (14 loc) · 1.93 KB

Index

  1. classes are objects too
  2. how to create a simple metaclass
  3. using namespace in metaclasses
  4. an awesome example using metaclass
  5. how to use metaclasses to create singleton classes in python
  6. how django rest framework uses metaclasses
  7. how django uses metaclasses to maintain backward compatability

how django uses metaclasses to maintain backward compatability

For the last example of this talk let's go over how django uses metaclass to maintain backward compatability. This usage of metaclass was introduced into the source code as a result of this issue. This issue says that over time there was a change in the naming convention in django. Initially get_queryset used to be get_query_set being one of the examples.

The conversation around this issue is also very interesting. The django community tried a lot of things. Amongst them was a decorator over the old function which raised a warning. But, people could still override the function rendering the decorator unused.

Here is the metaclass that now handles the backward compatabilty issue.

It defines the new method if missing and warns about it, defines the old method if missing and complains whenever an old method is called.

Here are the tests for the metaclass