1414}
1515
1616
17- def _setup_bind (cls : type ["Base" ]) -> None :
18- bind_key : str | None = getattr (cls , "__bind_key__" , None )
19-
20- if bind_key is None :
21- bind_key = ""
22-
23- cls .__table__ .info ["bind_key" ] = bind_key
24-
25-
2617_callbacks = []
2718
2819
29- def register_callback (callback : Callable [[type ["Base" ]], Any ]) -> None :
20+ def register_callback (callback : Callable [[type ["Base" ], dict [ str , Any ] ], Any ]) -> None :
3021 """
3122 Register a callback to be called when a new Base subclass is created.
32- The callback should accept a single argument, which is the subclass itself.
3323 """
3424 _callbacks .append (callback )
3525
3626
37- def remove_callback (callback : Callable [[type ["Base" ]], Any ]) -> None :
27+ def remove_callback (callback : Callable [[type ["Base" ], dict [ str , Any ] ], Any ]) -> None :
3828 """
3929 Remove a previously registered callback.
4030 """
@@ -51,7 +41,7 @@ class Base(AsyncAttrs, DeclarativeBase):
5141
5242 def __init_subclass__ (cls , ** kwargs ):
5343 for callback in _callbacks :
54- callback (cls )
44+ callback (cls , kwargs )
5545
5646 if not hasattr (cls , "__tablename__" ) and "tablename" in kwargs :
5747 cls .__tablename__ = kwargs ["tablename" ]
@@ -67,4 +57,9 @@ def __init_subclass__(cls, **kwargs):
6757 if not hasattr (cls , "__table__" ):
6858 return
6959
70- _setup_bind (cls )
60+ bind_key : str | None = getattr (cls , "__bind_key__" , kwargs .get ("bind_key" , None ))
61+
62+ if bind_key is None :
63+ bind_key = ""
64+
65+ cls .__table__ .info ["bind_key" ] = bind_key
0 commit comments