@@ -82,11 +82,18 @@ def on_config(self, config):
82
82
# Invoke `on_startup` event for plugins in group
83
83
command = "serve" if self .is_serve else "build"
84
84
for method in option .plugins .events ["startup" ]:
85
- if method .__self__ in self .plugins .values ():
85
+ plugin = self ._get_plugin (method )
86
+
87
+ # Ensure that we have a method bound to a plugin (and not a hook)
88
+ if plugin and plugin in self .plugins .values ():
86
89
method (command = command , dirty = self .is_dirty )
87
90
88
91
# -------------------------------------------------------------------------
89
92
93
+ # Retrieve plugin instance for bound method or nothing
94
+ def _get_plugin (self , method : Callable ):
95
+ return getattr (method , "__self__" , None )
96
+
90
97
# Retrieve priority of plugin method
91
98
def _get_priority (self , method : Callable ):
92
99
return getattr (method , "mkdocs_priority" , 0 )
@@ -117,17 +124,23 @@ def _patch(self, methods: list[Callable], config: MkDocsConfig):
117
124
head = methods [at ]
118
125
119
126
# Skip if the plugin is not part of the group
120
- if not head .__self__ in self .plugins .values ():
127
+ plugin = self ._get_plugin (head )
128
+ if not plugin or plugin not in self .plugins .values ():
121
129
continue
122
130
123
131
# Skip if the previous method has a higher priority than the current
124
132
# one, because we know we can't swap them anyway
125
133
if self ._get_priority (tail ) > self ._get_priority (head ):
126
134
continue
127
135
136
+ # Ensure that we have a method bound to a plugin (and not a hook)
137
+ plugin = self ._get_plugin (tail )
138
+ if not plugin :
139
+ continue
140
+
128
141
# Both methods have the same priority, so we check if the ordering
129
142
# of both methods is violated, and if it is, swap them
130
- if (position < self ._get_position (tail . __self__ , config )):
143
+ if (position < self ._get_position (plugin , config )):
131
144
methods [at ], methods [at - 1 ] = tail , head
132
145
133
146
# -----------------------------------------------------------------------------
0 commit comments