77
88from flask import url_for
99
10- from typing import List , Dict , Callable
10+ from typing import List , Dict , Callable , Union
1111
1212from .utilities import camel_to_snake , get_docstring , snake_to_spine
1313from .views .builder import static_from
@@ -36,11 +36,11 @@ def __init__(
3636 self ._meta : dict = {} # Extra metadata to add to the extension description
3737
3838 self ._on_registers : List [
39- Dict
39+ Union [ Dict , Callable ]
4040 ] = [] # List of dictionaries of functions to run on registration
4141
4242 self ._on_components : List [
43- Dict
43+ Union [ Dict , Callable ]
4444 ] = [] # List of dictionaries of functions to run as components are added
4545
4646 self ._cls = str (self ) # String description of extension instance
@@ -64,6 +64,14 @@ def views(self):
6464 """ """
6565 return self ._views
6666
67+ @property
68+ def on_components (self ):
69+ return self ._on_components
70+
71+ @property
72+ def on_registers (self ):
73+ return self ._on_registers
74+
6775 def add_view (self , view_class , * urls , endpoint = None , ** kwargs ):
6876 """
6977
@@ -217,7 +225,7 @@ def find_instances_in_module(module, class_to_find):
217225 for attribute in dir (module ):
218226 if not attribute .startswith ("__" ):
219227 if isinstance (getattr (module , attribute ), class_to_find ):
220- logging .debug (f "Found extension { getattr (module , attribute ).name } " )
228+ logging .debug ("Found extension %s" , getattr (module , attribute ).name )
221229 objs .append (getattr (module , attribute ))
222230 return objs
223231
@@ -235,17 +243,19 @@ def find_extensions_in_file(extension_path: str, module_name="extensions") -> li
235243 :rtype: list
236244
237245 """
238- logging .debug (f "Loading extensions from { extension_path } " )
246+ logging .debug ("Loading extensions from %s" , extension_path )
239247
240248 spec = util .spec_from_file_location (module_name , extension_path )
241249 mod = util .module_from_spec (spec )
242250 sys .modules [spec .name ] = mod
243251
244252 try :
245253 spec .loader .exec_module (mod ) # type: ignore
246- except Exception : # skipcq: PYL-W0703
254+ except Exception : # pylint: disable=broad-except
247255 logging .error (
248- f"Exception in extension path { extension_path } : \n { traceback .format_exc ()} "
256+ "Exception in extension path %s: \n %s" ,
257+ extension_path ,
258+ traceback .format_exc (),
249259 )
250260 return []
251261 else :
@@ -270,7 +280,7 @@ def find_extensions(extension_dir: str, module_name="extensions") -> list:
270280 :rtype: list
271281
272282 """
273- logging .debug (f "Loading extensions from { extension_dir } " )
283+ logging .debug ("Loading extensions from %s" , extension_dir )
274284
275285 extensions = []
276286 extension_paths = glob .glob (os .path .join (extension_dir , "*.py" ))
0 commit comments