@@ -168,6 +168,7 @@ def _one(seq):
168168 return x
169169
170170
171+ @attrs .define (frozen = False )
171172class ThreadLocalInterpreter :
172173 """An interpeter used to execute a sequence of queries within the same thread and cursor.
173174
@@ -177,11 +178,6 @@ class ThreadLocalInterpreter:
177178 compiler : Compiler
178179 gen : Generator
179180
180- def __init__ (self , compiler : Compiler , gen : Generator ):
181- super ().__init__ ()
182- self .gen = gen
183- self .compiler = compiler
184-
185181 def apply_queries (self , callback : Callable [[str ], Any ]):
186182 q : Expr = next (self .gen )
187183 while True :
@@ -205,6 +201,7 @@ def apply_query(callback: Callable[[str], Any], sql_code: Union[str, ThreadLocal
205201 return callback (sql_code )
206202
207203
204+ @attrs .define (frozen = False )
208205class Mixin_Schema (AbstractMixin_Schema ):
209206 def table_information (self ) -> Compilable :
210207 return table ("information_schema" , "tables" )
@@ -221,6 +218,7 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
221218 )
222219
223220
221+ @attrs .define (frozen = False )
224222class Mixin_RandomSample (AbstractMixin_RandomSample ):
225223 def random_sample_n (self , tbl : ITable , size : int ) -> ITable :
226224 # TODO use a more efficient algorithm, when the table count is known
@@ -230,15 +228,17 @@ def random_sample_ratio_approx(self, tbl: ITable, ratio: float) -> ITable:
230228 return tbl .where (Random () < ratio )
231229
232230
231+ @attrs .define (frozen = False )
233232class Mixin_OptimizerHints (AbstractMixin_OptimizerHints ):
234233 def optimizer_hints (self , hints : str ) -> str :
235234 return f"/*+ { hints } */ "
236235
237236
237+ @attrs .define (frozen = False )
238238class BaseDialect (abc .ABC ):
239239 SUPPORTS_PRIMARY_KEY : ClassVar [bool ] = False
240240 SUPPORTS_INDEXES : ClassVar [bool ] = False
241- TYPE_CLASSES : ClassVar [Dict [str , type ]] = {}
241+ TYPE_CLASSES : ClassVar [Dict [str , Type [ ColType ] ]] = {}
242242 MIXINS = frozenset ()
243243
244244 PLACEHOLDER_TABLE = None # Used for Oracle
@@ -540,7 +540,7 @@ def render_select(self, parent_c: Compiler, elem: Select) -> str:
540540
541541 def render_join (self , parent_c : Compiler , elem : Join ) -> str :
542542 tables = [
543- t if isinstance (t , TableAlias ) else TableAlias (source_table = t , name = parent_c .new_unique_name ())
543+ t if isinstance (t , TableAlias ) else TableAlias (t , name = parent_c .new_unique_name ())
544544 for t in elem .source_tables
545545 ]
546546 c = parent_c .add_table_context (* tables , in_join = True , in_select = False )
@@ -839,6 +839,7 @@ def __getitem__(self, i):
839839 return self .rows [i ]
840840
841841
842+ @attrs .define (frozen = False )
842843class Database (abc .ABC ):
843844 """Base abstract class for databases.
844845
@@ -1114,22 +1115,22 @@ def is_autocommit(self) -> bool:
11141115 "Return whether the database autocommits changes. When false, COMMIT statements are skipped."
11151116
11161117
1118+ @attrs .define (frozen = False )
11171119class ThreadedDatabase (Database ):
11181120 """Access the database through singleton threads.
11191121
11201122 Used for database connectors that do not support sharing their connection between different threads.
11211123 """
11221124
1123- _init_error : Optional [Exception ]
1124- _queue : ThreadPoolExecutor
1125- thread_local : threading .local
1125+ thread_count : int = 1
1126+
1127+ _init_error : Optional [Exception ] = None
1128+ _queue : Optional [ThreadPoolExecutor ] = None
1129+ thread_local : threading .local = attrs .field (factory = threading .local )
11261130
1127- def __init__ (self , thread_count = 1 ):
1128- super ().__init__ ()
1129- self ._init_error = None
1130- self ._queue = ThreadPoolExecutor (thread_count , initializer = self .set_conn )
1131- self .thread_local = threading .local ()
1132- logger .info (f"[{ self .name } ] Starting a threadpool, size={ thread_count } ." )
1131+ def __attrs_post_init__ (self ):
1132+ self ._queue = ThreadPoolExecutor (self .thread_count , initializer = self .set_conn )
1133+ logger .info (f"[{ self .name } ] Starting a threadpool, size={ self .thread_count } ." )
11331134
11341135 def set_conn (self ):
11351136 assert not hasattr (self .thread_local , "conn" )
0 commit comments