@@ -12,16 +12,18 @@ def __init__(self, psqlpy) -> None:
1212 self .apilevel = "2.0"
1313 self .threadsafety = 2 # Threads may share the module and connections
1414
15- self .Warning = psqlpy .Error
16- self .Error = psqlpy .Error
17- self .InterfaceError = psqlpy .Error
18- self .DatabaseError = psqlpy .Error
19- self .DataError = psqlpy .Error
20- self .OperationalError = psqlpy .Error
21- self .IntegrityError = psqlpy .Error
22- self .InternalError = psqlpy .Error
23- self .ProgrammingError = psqlpy .Error
24- self .NotSupportedError = psqlpy .Error
15+ # Single reusable exception class for all error types
16+ _error_class = psqlpy .Error
17+ self .Warning = _error_class
18+ self .Error = _error_class
19+ self .InterfaceError = _error_class
20+ self .DatabaseError = _error_class
21+ self .DataError = _error_class
22+ self .OperationalError = _error_class
23+ self .IntegrityError = _error_class
24+ self .InternalError = _error_class
25+ self .ProgrammingError = _error_class
26+ self .NotSupportedError = _error_class
2527
2628 for k , v in self .psqlpy .__dict__ .items ():
2729 if k != "connect" :
@@ -39,34 +41,36 @@ def connect(self, *arg, **kw):
3941 # Add other server_settings mappings as needed
4042
4143 # Filter out any other unsupported parameters that SQLAlchemy might pass
42- supported_params = {
43- "dsn" ,
44- "username" ,
45- "password" ,
46- "host" ,
47- "hosts" ,
48- "port" ,
49- "ports" ,
50- "db_name" ,
51- "target_session_attrs" ,
52- "options" ,
53- "application_name" ,
54- "connect_timeout_sec" ,
55- "connect_timeout_nanosec" ,
56- "tcp_user_timeout_sec" ,
57- "tcp_user_timeout_nanosec" ,
58- "keepalives" ,
59- "keepalives_idle_sec" ,
60- "keepalives_idle_nanosec" ,
61- "keepalives_interval_sec" ,
62- "keepalives_interval_nanosec" ,
63- "keepalives_retries" ,
64- "load_balance_hosts" ,
65- "max_db_pool_size" ,
66- "conn_recycling_method" ,
67- "ssl_mode" ,
68- "ca_file" ,
69- }
44+ supported_params = frozenset (
45+ {
46+ "dsn" ,
47+ "username" ,
48+ "password" ,
49+ "host" ,
50+ "hosts" ,
51+ "port" ,
52+ "ports" ,
53+ "db_name" ,
54+ "target_session_attrs" ,
55+ "options" ,
56+ "application_name" ,
57+ "connect_timeout_sec" ,
58+ "connect_timeout_nanosec" ,
59+ "tcp_user_timeout_sec" ,
60+ "tcp_user_timeout_nanosec" ,
61+ "keepalives" ,
62+ "keepalives_idle_sec" ,
63+ "keepalives_idle_nanosec" ,
64+ "keepalives_interval_sec" ,
65+ "keepalives_interval_nanosec" ,
66+ "keepalives_retries" ,
67+ "load_balance_hosts" ,
68+ "max_db_pool_size" ,
69+ "conn_recycling_method" ,
70+ "ssl_mode" ,
71+ "ca_file" ,
72+ }
73+ )
7074
7175 filtered_kw = {k : v for k , v in kw .items () if k in supported_params }
7276
@@ -90,17 +94,18 @@ def __init__(self):
9094
9195 self ._adapt_dbapi = PSQLPyAdaptDBAPI (psqlpy )
9296
93- # Copy attributes from psqlpy for compatibility
94- self .Warning = psqlpy .Error
95- self .Error = psqlpy .Error
96- self .InterfaceError = psqlpy .Error
97- self .DatabaseError = psqlpy .Error
98- self .DataError = psqlpy .Error
99- self .OperationalError = psqlpy .Error
100- self .IntegrityError = psqlpy .Error
101- self .InternalError = psqlpy .Error
102- self .ProgrammingError = psqlpy .Error
103- self .NotSupportedError = psqlpy .Error
97+ # Single reusable exception class for all error types
98+ _error_class = psqlpy .Error
99+ self .Warning = _error_class
100+ self .Error = _error_class
101+ self .InterfaceError = _error_class
102+ self .DatabaseError = _error_class
103+ self .DataError = _error_class
104+ self .OperationalError = _error_class
105+ self .IntegrityError = _error_class
106+ self .InternalError = _error_class
107+ self .ProgrammingError = _error_class
108+ self .NotSupportedError = _error_class
104109
105110 # Type constructors
106111 def Date (self , year , month , day ):
0 commit comments