6
6
from django .utils .module_loading import import_by_path
7
7
8
8
9
- def get_override_class (proxy_class , default_class ):
9
+ def get_override_class (proxy_class , default_class = None ):
10
+ """Determine which class to use in an override class
11
+
12
+ The `proxy_class` is the main class that is used, and `default_class` is the
13
+ default class that this proxy class will instantiate. If `default_class` is
14
+ not defined, this will be inferred from the `proxy_class`, as is defined in
15
+ :py:cls:`SettingsOverrideObject`.
16
+ """
17
+ if default_class is None :
18
+ default_class = getattr (proxy_class , '_default_class' )
10
19
class_id = '.' .join ([
11
20
inspect .getmodule (proxy_class ).__name__ ,
12
21
proxy_class .__name__
@@ -33,22 +42,23 @@ class SettingsOverrideObject(object):
33
42
"""Base class for creating class that can be overridden
34
43
35
44
This is used for extension points in the code, where we want to extend a
36
- class without monkey patching it. This abstract class allows for lazy
37
- inheritance, creating a class from the specified class or from a setting,
38
- but only once the class is called .
45
+ class without monkey patching it. This class will proxy classmethod calls
46
+ and instantiation to an underlying class, determined by used of
47
+ :py:cvar:`_default_class` or an override class from settings .
39
48
40
- Default to an instance of the class defined by :py:cvar:`_default_class`.
49
+ The default target class is defined by :py:cvar:`_default_class`.
41
50
42
- Next, look for an override setting class path in
43
- ``settings.CLASS_OVERRIDES``, which should be a dictionary of class paths.
44
- The setting should be a dictionary keyed by the object path name ::
51
+ To override this class, an override setting class path can be added to
52
+ ``settings.CLASS_OVERRIDES``. This settings should be a dictionary keyed by
53
+ source class paths, with values to the override classes ::
45
54
46
55
CLASS_OVERRIDES = {
47
56
'readthedocs.core.resolver.Resolver': 'something.resolver.Resolver',
48
57
}
49
58
50
59
Lastly, if ``settings.CLASS_OVERRIDES`` is missing, or the key is not found,
51
- attempt to pull the key :py:cvar:`_override_setting` from ``settings``.
60
+ attempt to pull the key :py:cvar:`_override_setting` from ``settings``. This
61
+ matches the pattern we've been using previously.
52
62
"""
53
63
54
64
__metaclass__ = SettingsOverrideMeta
@@ -59,7 +69,7 @@ class without monkey patching it. This abstract class allows for lazy
59
69
def __new__ (cls , * args , ** kwargs ):
60
70
"""Set up wrapped object
61
71
62
- Create an instance of the underlying proxy class and return instead of
72
+ Create an instance of the underlying target class and return instead of
63
73
this class.
64
74
"""
65
75
return get_override_class (cls , cls ._default_class )(* args , ** kwargs )
0 commit comments