@@ -885,7 +885,7 @@ def bind(self, connection: Connection) -> Schema:
885
885
raise Error ("Call to 'bind' not allowed for embedded Schema." )
886
886
self ._con = connection
887
887
self ._ic = self ._con .transaction_manager (tpb (Isolation .READ_COMMITTED_RECORD_VERSION ,
888
- access = TraAccessMode .READ )).cursor ()
888
+ access_mode = TraAccessMode .READ )).cursor ()
889
889
self ._ic ._logging_id_ = 'schema.internal_cursor'
890
890
self .__clear ()
891
891
self .ods = self ._con .info .ods
@@ -1116,7 +1116,7 @@ def get_item(self, name: str, itype: ObjectType, subname: str=None) -> SchemaIte
1116
1116
return self .all_functions .get (name )
1117
1117
elif itype is ObjectType .COLLATION :
1118
1118
return self .collations .get (name )
1119
- elif itype in [ ObjectType .PACKAGE , ObjectType .PACKAGE_BODY ] : # Package
1119
+ elif itype in ( ObjectType .PACKAGE , ObjectType .PACKAGE_BODY ) : # Package
1120
1120
return self .packages .get (name )
1121
1121
def get_metadata_ddl (self , * , sections = SCRIPT_DEFAULT_ORDER ) -> List [str ]:
1122
1122
"""Return list of DDL SQL commands for creation of specified categories of database objects.
@@ -1174,7 +1174,8 @@ def view_dependencies(item):
1174
1174
script .append (domain .get_sql_for ('create' ))
1175
1175
elif section == Section .PACKAGE_DEFS :
1176
1176
for package in self .packages :
1177
- script .append (package .get_sql_for ('create' ))
1177
+ if not package .is_sys_object ():
1178
+ script .append (package .get_sql_for ('create' ))
1178
1179
elif section == Section .FUNCTION_DEFS :
1179
1180
for func in (x for x in self .functions if
1180
1181
not x .is_external () and
@@ -1211,7 +1212,8 @@ def view_dependencies(item):
1211
1212
script .append (view .get_sql_for ('create' ))
1212
1213
elif section == Section .PACKAGE_BODIES :
1213
1214
for package in self .packages :
1214
- script .append (package .get_sql_for ('create' , body = True ))
1215
+ if not package .is_sys_object ():
1216
+ script .append (package .get_sql_for ('create' , body = True ))
1215
1217
elif section == Section .PROCEDURE_BODIES :
1216
1218
for proc in (x for x in self .procedures if not x .is_packaged ()):
1217
1219
script .append ('ALTER' + proc .get_sql_for ('create' )[6 :])
@@ -1232,12 +1234,12 @@ def view_dependencies(item):
1232
1234
and not x .subject .is_sys_object ()):
1233
1235
script .append (priv .get_sql_for ('grant' ))
1234
1236
elif section == Section .COMMENTS :
1235
- for objects in [ self .character_sets , self .collations ,
1237
+ for objects in ( self .character_sets , self .collations ,
1236
1238
self .exceptions , self .domains ,
1237
1239
self .generators , self .tables ,
1238
1240
self .indices , self .views ,
1239
1241
self .triggers , self .procedures ,
1240
- self .functions , self .roles ] :
1242
+ self .functions , self .roles ) :
1241
1243
for obj in objects :
1242
1244
if obj .description is not None :
1243
1245
script .append (obj .get_sql_for ('comment' ))
@@ -1653,7 +1655,7 @@ def __init__(self, schema: Schema, attributes: Dict[str, Any]):
1653
1655
#: Weak reference to parent `.Schema` instance.
1654
1656
self .schema : Schema = schema if isinstance (schema , weakref .ProxyType ) else weakref .proxy (schema )
1655
1657
self ._type_code : List [ObjectType ] = []
1656
- self ._attributes : Dict [str , Any ] = dict ( attributes )
1658
+ self ._attributes : Dict [str , Any ] = attributes
1657
1659
self ._actions : List [str ] = []
1658
1660
def _strip_attribute (self , attr : str ) -> None :
1659
1661
if self ._attributes .get (attr ):
@@ -1668,7 +1670,7 @@ def _needs_quoting(self, ident: str) -> bool:
1668
1670
return False
1669
1671
if self .schema .opt_always_quote :
1670
1672
return True
1671
- if len ( ident ) >= 1 and ident [0 ] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :
1673
+ if ident and ident [0 ] not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :
1672
1674
return True
1673
1675
for char in ident :
1674
1676
if char not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_' :
@@ -2596,7 +2598,7 @@ def datatype(self) -> str:
2596
2598
precision_known = False
2597
2599
if self .field_type in (FieldType .SHORT , FieldType .LONG , FieldType .INT64 ):
2598
2600
if self .precision is not None :
2599
- if self .sub_type in [ FieldSubType .NUMERIC , FieldSubType .DECIMAL ] :
2601
+ if self .sub_type in ( FieldSubType .NUMERIC , FieldSubType .DECIMAL ) :
2600
2602
l .append (f'{ INTEGRAL_SUBTYPES [self .sub_type ]} ({ self .precision } , { - self .scale } )' )
2601
2603
precision_known = True
2602
2604
if not precision_known :
@@ -2710,7 +2712,7 @@ def dependent(self) -> SchemaItem:
2710
2712
return None
2711
2713
elif self .dependent_type == 17 : # Collation
2712
2714
return self .schema .collations .get (self .dependent_name )
2713
- elif self .dependent_type in [ 18 , 19 ] : # Package + package body
2715
+ elif self .dependent_type in ( 18 , 19 ) : # Package + package body
2714
2716
return self .schema .packages .get (self .dependent_name )
2715
2717
return None
2716
2718
@property
@@ -2904,8 +2906,7 @@ def trigger_names(self) -> List[str]:
2904
2906
"""
2905
2907
if self .is_check ():
2906
2908
return self ._attributes ['RDB$TRIGGER_NAME' ]
2907
- else :
2908
- return []
2909
+ return []
2909
2910
@property
2910
2911
def triggers (self ) -> DataList [Trigger ]:
2911
2912
"""List of triggers that enforce the CHECK constraint.
@@ -3056,12 +3057,12 @@ def _get_name(self) -> str:
3056
3057
def is_gtt (self ) -> bool :
3057
3058
"""Returns True if table is GLOBAL TEMPORARY table.
3058
3059
"""
3059
- return self .table_type in [ RelationType .GLOBAL_TEMPORARY_DELETE ,
3060
- RelationType .GLOBAL_TEMPORARY_PRESERVE ]
3060
+ return self .table_type in ( RelationType .GLOBAL_TEMPORARY_DELETE ,
3061
+ RelationType .GLOBAL_TEMPORARY_PRESERVE )
3061
3062
def is_persistent (self ) -> bool :
3062
3063
"""Returns True if table is persistent one.
3063
3064
"""
3064
- return self .table_type in [ RelationType .PERSISTENT , RelationType .EXTERNAL ]
3065
+ return self .table_type in ( RelationType .PERSISTENT , RelationType .EXTERNAL )
3065
3066
def is_external (self ) -> bool :
3066
3067
"""Returns True if table is external table.
3067
3068
"""
@@ -3938,8 +3939,7 @@ def __init__(self, schema: Schema, function: Function, attributes: Dict[str, Any
3938
3939
self ._strip_attribute ('RDB$RELATION_NAME' )
3939
3940
self ._strip_attribute ('RDB$DESCRIPTION' )
3940
3941
def _get_name (self ) -> str :
3941
- return self .argument_name if self .argument_name \
3942
- else f'{ self .function .name } _{ self .position } '
3942
+ return self .argument_name or f'{ self .function .name } _{ self .position } '
3943
3943
def get_sql_definition (self ) -> str :
3944
3944
"""Returns SQL definition for parameter.
3945
3945
"""
@@ -3962,16 +3962,16 @@ def is_by_value(self) -> bool:
3962
3962
def is_by_reference (self ) -> bool :
3963
3963
"""Returns True if argument is passed by reference.
3964
3964
"""
3965
- return self .mechanism in [ Mechanism .BY_REFERENCE , Mechanism .BY_REFERENCE_WITH_NULL ]
3965
+ return self .mechanism in ( Mechanism .BY_REFERENCE , Mechanism .BY_REFERENCE_WITH_NULL )
3966
3966
def is_by_descriptor (self , any = False ) -> bool :
3967
3967
"""Returns True if argument is passed by descriptor.
3968
3968
3969
3969
Arguments:
3970
3970
any: If True, method returns True if any kind of descriptor is used (including
3971
3971
BLOB and ARRAY descriptors).
3972
3972
"""
3973
- return self .mechanism in [ Mechanism .BY_VMS_DESCRIPTOR , Mechanism .BY_ISC_DESCRIPTOR ,
3974
- Mechanism .BY_SCALAR_ARRAY_DESCRIPTOR ] if any \
3973
+ return self .mechanism in ( Mechanism .BY_VMS_DESCRIPTOR , Mechanism .BY_ISC_DESCRIPTOR ,
3974
+ Mechanism .BY_SCALAR_ARRAY_DESCRIPTOR ) if any \
3975
3975
else self .mechanism == Mechanism .BY_VMS_DESCRIPTOR
3976
3976
def is_with_null (self ) -> bool :
3977
3977
"""Returns True if argument is passed by reference with NULL support.
@@ -4016,7 +4016,7 @@ def mechanism(self) -> Mechanism:
4016
4016
def field_type (self ) -> FieldType :
4017
4017
"""Number code of the data type defined for the argument.
4018
4018
"""
4019
- return None if (code := self ._attributes ['RDB$FIELD_TYPE' ]) is None else FieldType (code )
4019
+ return None if (code := self ._attributes ['RDB$FIELD_TYPE' ]) in ( None , 0 ) else FieldType (code )
4020
4020
@property
4021
4021
def length (self ) -> int :
4022
4022
"""Length of the argument in bytes.
@@ -4070,7 +4070,7 @@ def datatype(self) -> str:
4070
4070
precision_known = False
4071
4071
if self .field_type in (FieldType .SHORT , FieldType .LONG , FieldType .INT64 ):
4072
4072
if self .precision != None :
4073
- if self .sub_type in [ FieldSubType .NUMERIC , FieldSubType .DECIMAL ] :
4073
+ if self .sub_type in ( FieldSubType .NUMERIC , FieldSubType .DECIMAL ) :
4074
4074
l .append (f'{ INTEGRAL_SUBTYPES [self .sub_type ]} ({ self .precision } , { - self .scale } )' )
4075
4075
precision_known = True
4076
4076
if not precision_known :
@@ -4224,7 +4224,7 @@ def _get_create_sql(self, **params) -> str:
4224
4224
def _get_alter_sql (self , ** params ) -> str :
4225
4225
self ._check_params (params , ['arguments' , 'returns' , 'declare' , 'code' ])
4226
4226
arguments = params .get ('arguments' )
4227
- for par in [ 'returns' , 'code' ] :
4227
+ for par in ( 'returns' , 'code' ) :
4228
4228
if par not in params :
4229
4229
raise ValueError (f"Missing required parameter: '{ par } '" )
4230
4230
returns = params .get ('returns' )
@@ -4280,7 +4280,7 @@ def _load_arguments(self, mock: Dict[str, Any]=None) -> None:
4280
4280
'RDB$ARGUMENT_MECHANISM' , 'RDB$FIELD_NAME' , 'RDB$RELATION_NAME' ,
4281
4281
'RDB$SYSTEM_FLAG' , 'RDB$DESCRIPTION' ]
4282
4282
self .__arguments = DataList ((FunctionArgument (self .schema , self , row ) for row in
4283
- (mock if mock else
4283
+ (mock or
4284
4284
self .schema ._select ("""select %s from rdb$function_arguments
4285
4285
where rdb$function_name = ? order by rdb$argument_position""" % ',' .join (cols ), (self .name ,)))),
4286
4286
FunctionArgument , frozen = True )
0 commit comments