@@ -142,10 +142,12 @@ def _encode_timestamp(v: Union[datetime.datetime, datetime.date]) -> bytes:
142
142
143
143
def _is_fixed_point (dialect : int , datatype : SQLDataType , subtype : int ,
144
144
scale : int ) -> bool :
145
- return ((datatype in [SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ]
146
- and (subtype or scale )) or
145
+ return ((datatype in (SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 )
146
+ and (subtype or scale ))
147
+ or
147
148
((dialect < 3 ) and scale
148
- and (datatype in [SQLDataType .DOUBLE , SQLDataType .D_FLOAT ])))
149
+ and (datatype in (SQLDataType .DOUBLE , SQLDataType .D_FLOAT )))
150
+ )
149
151
150
152
def _get_external_data_type_name (dialect : int , datatype : SQLDataType ,
151
153
subtype : int , scale : int ) -> str :
@@ -168,7 +170,7 @@ def _get_external_data_type_name(dialect: int, datatype: SQLDataType,
168
170
return 'BIGINT'
169
171
elif datatype == SQLDataType .FLOAT :
170
172
return 'FLOAT'
171
- elif datatype in [ SQLDataType .DOUBLE , SQLDataType .D_FLOAT ] :
173
+ elif datatype in ( SQLDataType .DOUBLE , SQLDataType .D_FLOAT ) :
172
174
return 'DOUBLE'
173
175
elif datatype == SQLDataType .TIMESTAMP :
174
176
return 'TIMESTAMP'
@@ -184,7 +186,7 @@ def _get_external_data_type_name(dialect: int, datatype: SQLDataType,
184
186
return 'UNKNOWN'
185
187
186
188
def _get_internal_data_type_name (data_type : SQLDataType ) -> str :
187
- if data_type in [ SQLDataType .DOUBLE , SQLDataType .D_FLOAT ] :
189
+ if data_type in ( SQLDataType .DOUBLE , SQLDataType .D_FLOAT ) :
188
190
value = SQLDataType .DOUBLE
189
191
else :
190
192
value = data_type
@@ -215,7 +217,7 @@ def _check_integer_range(value: int, dialect: int, datatype: SQLDataType,
215
217
216
218
def _is_str_param (value : Any , datatype : SQLDataType ) -> bool :
217
219
return ((isinstance (value , str ) and datatype != SQLDataType .BLOB ) or
218
- datatype in [ SQLDataType .TEXT , SQLDataType .VARYING ] )
220
+ datatype in ( SQLDataType .TEXT , SQLDataType .VARYING ) )
219
221
220
222
def create_meta_descriptors (meta : iMessageMetadata ) -> List [ItemMetadata ]:
221
223
result = []
@@ -364,7 +366,7 @@ def get_buffer(self) -> bytes:
364
366
isolation = (Isolation .READ_COMMITTED_RECORD_VERSION
365
367
if self .isolation == Isolation .READ_COMMITTED
366
368
else self .isolation )
367
- if isolation in [ Isolation .SNAPSHOT , Isolation .SERIALIZABLE ] :
369
+ if isolation in ( Isolation .SNAPSHOT , Isolation .SERIALIZABLE ) :
368
370
tpb .insert_tag (isolation )
369
371
elif isolation == Isolation .READ_COMMITTED_READ_CONSISTENCY :
370
372
tpb .insert_tag (TPBItem .READ_CONSISTENCY )
@@ -777,7 +779,7 @@ def callback(result, length, updated):
777
779
self .__queue : PriorityQueue = weakref .proxy (queue )
778
780
self ._db_handle : a .FB_API_HANDLE = db_handle
779
781
self ._isc_status : a .ISC_STATUS_ARRAY = a .ISC_STATUS_ARRAY (0 )
780
- self .event_names : List [str ] = list ( event_names )
782
+ self .event_names : List [str ] = event_names
781
783
782
784
self .__results : a .RESULT_VECTOR = a .RESULT_VECTOR (0 )
783
785
self .__closed : bool = False
@@ -1700,7 +1702,7 @@ def _determine_field_precision(self, meta: ItemMetadata) -> int:
1700
1702
# for example for queries with dynamically computed fields
1701
1703
return 0
1702
1704
# Special case for automatic RDB$DB_KEY fields.
1703
- if (meta .field in [ 'DB_KEY' , 'RDB$DB_KEY' ] ):
1705
+ if (meta .field in ( 'DB_KEY' , 'RDB$DB_KEY' ) ):
1704
1706
return 0
1705
1707
precision = self .__precision_cache .get ((meta .relation , meta .field ))
1706
1708
if precision is not None :
@@ -1860,8 +1862,7 @@ def transaction_manager(self, default_tpb: bytes=None,
1860
1862
default_action: Default action to be performed on implicit transaction end.
1861
1863
"""
1862
1864
assert self ._att is not None
1863
- transaction = TransactionManager (self , default_tpb if default_tpb else self .default_tpb ,
1864
- default_action )
1865
+ transaction = TransactionManager (self , default_tpb or self .default_tpb , default_action )
1865
1866
self ._transactions .append (transaction )
1866
1867
return transaction
1867
1868
def begin (self , tpb : bytes = None ) -> None :
@@ -2241,9 +2242,8 @@ def __isolation(self) -> Isolation:
2241
2242
if cnt == 1 :
2242
2243
# The value is `TraInfoIsolation` that maps to `Isolation`
2243
2244
return Isolation (self .response .read_byte ())
2244
- else :
2245
- # The values are `TraInfoIsolation` + `TraInfoReadCommitted` that maps to `Isolation`
2246
- return Isolation (self .response .read_byte () + self .response .read_byte ())
2245
+ # The values are `TraInfoIsolation` + `TraInfoReadCommitted` that maps to `Isolation`
2246
+ return Isolation (self .response .read_byte () + self .response .read_byte ())
2247
2247
def __access (self ) -> TraInfoAccess :
2248
2248
return TraInfoAccess (self .response .read_sized_int ())
2249
2249
def __lock_timeout (self ) -> int :
@@ -2421,7 +2421,7 @@ def begin(self, tpb: bytes=None) -> None:
2421
2421
"""
2422
2422
assert not self .__closed
2423
2423
self ._finish () # Make sure that previous transaction (if any) is ended
2424
- self ._tra = self ._connection ()._att .start_transaction (tpb if tpb else self .default_tpb )
2424
+ self ._tra = self ._connection ()._att .start_transaction (tpb or self .default_tpb )
2425
2425
def commit (self , * , retaining : bool = False ) -> None :
2426
2426
"""Commits the transaction managed by this instance.
2427
2427
@@ -2561,7 +2561,7 @@ def begin(self, tpb: bytes=None) -> None:
2561
2561
self ._finish () # Make sure that previous transaction (if any) is ended
2562
2562
with self ._dtc .start_builder () as builder :
2563
2563
for con in self ._connections :
2564
- builder .add_with_tpb (con ._att , tpb if tpb else self .default_tpb )
2564
+ builder .add_with_tpb (con ._att , tpb or self .default_tpb )
2565
2565
self ._tra = builder .start ()
2566
2566
def prepare (self ) -> None :
2567
2567
"""Manually triggers the first phase of a two-phase commit (2PC).
@@ -3296,12 +3296,12 @@ def _pack_input(self, meta: iMessageMetadata, buffer: bytes,
3296
3296
value = str (value )
3297
3297
if isinstance (value , str ) and self ._encoding :
3298
3298
value = value .encode (self ._encoding )
3299
- if (datatype in [ SQLDataType .TEXT , SQLDataType .VARYING ]
3299
+ if (datatype in ( SQLDataType .TEXT , SQLDataType .VARYING )
3300
3300
and len (value ) > length ):
3301
3301
raise ValueError (f"Value of parameter ({ i } ) is too long,"
3302
3302
f" expected { length } , found { len (value )} " )
3303
3303
memmove (buf_addr + offset , value , len (value ))
3304
- elif datatype in [ SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ] :
3304
+ elif datatype in ( SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ) :
3305
3305
# It's scalled integer?
3306
3306
scale = in_meta .get_scale (i )
3307
3307
if in_meta .get_subtype (i ) or scale :
@@ -3471,7 +3471,7 @@ def _unpack_output(self) -> Tuple:
3471
3471
value = value .decode (self ._encoding )
3472
3472
elif datatype == SQLDataType .BOOLEAN :
3473
3473
value = bool ((0 ).from_bytes (buffer [offset ], 'little' ))
3474
- elif datatype in [ SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ] :
3474
+ elif datatype in ( SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ) :
3475
3475
value = (0 ).from_bytes (buffer [offset :offset + length ], 'little' , signed = True )
3476
3476
# It's scalled integer?
3477
3477
if desc .subtype or desc .scale :
@@ -3832,8 +3832,7 @@ def fetch_next(self) -> Optional[Tuple]:
3832
3832
self ._last_fetch_status = self ._result .fetch_next (self ._stmt ._out_buffer )
3833
3833
if self ._last_fetch_status == StateResult .OK :
3834
3834
return self ._unpack_output ()
3835
- else :
3836
- return None
3835
+ return None
3837
3836
def fetch_prior (self ) -> Optional [Tuple ]:
3838
3837
"""Fetch the previous row of a scrollable query result set.
3839
3838
@@ -3843,8 +3842,7 @@ def fetch_prior(self) -> Optional[Tuple]:
3843
3842
self ._last_fetch_status = self ._result .fetch_prior (self ._stmt ._out_buffer )
3844
3843
if self ._last_fetch_status == StateResult .OK :
3845
3844
return self ._unpack_output ()
3846
- else :
3847
- return None
3845
+ return None
3848
3846
def fetch_first (self ) -> Optional [Tuple ]:
3849
3847
"""Fetch the first row of a scrollable query result set.
3850
3848
@@ -3854,8 +3852,7 @@ def fetch_first(self) -> Optional[Tuple]:
3854
3852
self ._last_fetch_status = self ._result .fetch_first (self ._stmt ._out_buffer )
3855
3853
if self ._last_fetch_status == StateResult .OK :
3856
3854
return self ._unpack_output ()
3857
- else :
3858
- return None
3855
+ return None
3859
3856
def fetch_last (self ) -> Optional [Tuple ]:
3860
3857
"""Fetch the last row of a scrollable query result set.
3861
3858
@@ -3865,8 +3862,7 @@ def fetch_last(self) -> Optional[Tuple]:
3865
3862
self ._last_fetch_status = self ._result .fetch_last (self ._stmt ._out_buffer )
3866
3863
if self ._last_fetch_status == StateResult .OK :
3867
3864
return self ._unpack_output ()
3868
- else :
3869
- return None
3865
+ return None
3870
3866
def fetch_absolute (self , position : int ) -> Optional [Tuple ]:
3871
3867
"""Fetch the row of a scrollable query result set specified by absolute position.
3872
3868
@@ -3879,8 +3875,7 @@ def fetch_absolute(self, position: int) -> Optional[Tuple]:
3879
3875
self ._last_fetch_status = self ._result .fetch_absolute (position , self ._stmt ._out_buffer )
3880
3876
if self ._last_fetch_status == StateResult .OK :
3881
3877
return self ._unpack_output ()
3882
- else :
3883
- return None
3878
+ return None
3884
3879
def fetch_relative (self , offset : int ) -> Optional [Tuple ]:
3885
3880
"""Fetch the row of a scrollable query result set specified by relative position.
3886
3881
@@ -3894,8 +3889,7 @@ def fetch_relative(self, offset: int) -> Optional[Tuple]:
3894
3889
self ._last_fetch_status = self ._result .fetch_relative (offset , self ._stmt ._out_buffer )
3895
3890
if self ._last_fetch_status == StateResult .OK :
3896
3891
return self ._unpack_output ()
3897
- else :
3898
- return None
3892
+ return None
3899
3893
def setinputsizes (self , sizes : Sequence [Type ]) -> None :
3900
3894
"""Required by Python DB API 2.0, but pointless for Firebird, so it does nothing.
3901
3895
"""
@@ -3946,15 +3940,15 @@ def description(self) -> Tuple[DESCRIPTION]:
3946
3940
for meta in self ._stmt ._out_desc :
3947
3941
scale = meta .scale
3948
3942
precision = 0
3949
- if meta .datatype in [ SQLDataType .TEXT , SQLDataType .VARYING ] :
3943
+ if meta .datatype in ( SQLDataType .TEXT , SQLDataType .VARYING ) :
3950
3944
vtype = str
3951
3945
if meta .subtype in (4 , 69 ): # UTF8 and GB18030
3952
3946
dispsize = meta .length // 4
3953
3947
elif meta .subtype == 3 : # UNICODE_FSS
3954
3948
dispsize = meta .length // 3
3955
3949
else :
3956
3950
dispsize = meta .length
3957
- elif (meta .datatype in [ SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 ]
3951
+ elif (meta .datatype in ( SQLDataType .SHORT , SQLDataType .LONG , SQLDataType .INT64 )
3958
3952
and (meta .subtype or meta .scale )):
3959
3953
vtype = decimal .Decimal
3960
3954
precision = self ._connection ._determine_field_precision (meta )
@@ -3968,7 +3962,7 @@ def description(self) -> Tuple[DESCRIPTION]:
3968
3962
elif meta .datatype == SQLDataType .INT64 :
3969
3963
vtype = int
3970
3964
dispsize = 20
3971
- elif meta .datatype in [ SQLDataType .FLOAT , SQLDataType .D_FLOAT , SQLDataType .DOUBLE ] :
3965
+ elif meta .datatype in ( SQLDataType .FLOAT , SQLDataType .D_FLOAT , SQLDataType .DOUBLE ) :
3972
3966
# Special case, dialect 1 DOUBLE/FLOAT
3973
3967
# could be Fixed point
3974
3968
if (self ._stmt ._dialect < 3 ) and meta .scale :
@@ -4023,10 +4017,10 @@ def affected_rows(self) -> int:
4023
4017
if self ._stmt is None :
4024
4018
return - 1
4025
4019
result = - 1
4026
- if (self ._executed and self ._stmt .type in [ StatementType .SELECT ,
4020
+ if (self ._executed and self ._stmt .type in ( StatementType .SELECT ,
4027
4021
StatementType .INSERT ,
4028
4022
StatementType .UPDATE ,
4029
- StatementType .DELETE ] ):
4023
+ StatementType .DELETE ) ):
4030
4024
info = create_string_buffer (64 )
4031
4025
self ._stmt ._istmt .get_info (bytes ([23 , 1 ]), info ) # bytes(isc_info_sql_records, isc_info_end)
4032
4026
if ord (info [0 ]) != 23 : # pragma: no cover
@@ -4512,7 +4506,7 @@ def local_restore(self, *, backup_stream: BinaryIO,
4512
4506
else : # pragma: no cover
4513
4507
raise InterfaceError (f"Service responded with error code: { tag } " )
4514
4508
tag = self ._srv ().response .get_tag ()
4515
- keep_going = no_data or request_length != 0 or len ( line ) > 0
4509
+ keep_going = no_data or request_length != 0 or line
4516
4510
def nbackup (self , * , database : FILESPEC , backup : FILESPEC , level : int = 0 ,
4517
4511
direct : bool = None , flags : SrvNBackupFlag = SrvNBackupFlag .NONE ,
4518
4512
role : str = None , guid : str = None ) -> None :
@@ -5301,10 +5295,9 @@ def _reset_output(self) -> None:
5301
5295
def _make_request (self , timeout : int ) -> bytes :
5302
5296
if timeout == - 1 :
5303
5297
return None
5304
- else :
5305
- return b'' .join ([SrvInfoCode .TIMEOUT .to_bytes (1 , 'little' ),
5306
- (4 ).to_bytes (2 , 'little' ),
5307
- timeout .to_bytes (4 , 'little' ), isc_info_end .to_bytes (1 , 'little' )])
5298
+ return b'' .join ([SrvInfoCode .TIMEOUT .to_bytes (1 , 'little' ),
5299
+ (4 ).to_bytes (2 , 'little' ),
5300
+ timeout .to_bytes (4 , 'little' ), isc_info_end .to_bytes (1 , 'little' )])
5308
5301
def _fetch_complex_info (self , request : bytes , timeout : int = - 1 ) -> None :
5309
5302
send = self ._make_request (timeout )
5310
5303
self .response .clear ()
@@ -5494,7 +5487,7 @@ def connect_server(server: str, *, user: str=None, password: str=None,
5494
5487
srv_config = driver_config .get_server (server )
5495
5488
if srv_config is None :
5496
5489
srv_config = driver_config .server_defaults
5497
- host = server if server else None
5490
+ host = server or None
5498
5491
else :
5499
5492
host = srv_config .host .value
5500
5493
if host is None :
0 commit comments