@@ -25,7 +25,7 @@ def collect_prev_forks(fork: str) -> list[str]:
25
25
def requires_mypy_type_ignore (value : str ) -> bool :
26
26
return (
27
27
value .startswith (('ByteVector' ))
28
- or (value .startswith (('Vector' )) and 'floorlog2' in value )
28
+ or (value .startswith (('Vector' )) and any ( k in value for k in [ 'ceillog2' , 'floorlog2' ]) )
29
29
)
30
30
31
31
@@ -41,15 +41,19 @@ def objects_to_spec(preset_name: str,
41
41
"""
42
42
Given all the objects that constitute a spec, combine them into a single pyfile.
43
43
"""
44
- new_type_definitions = (
45
- '\n \n ' .join (
46
- [
47
- f"class { key } ({ value } ):\n pass\n " if not requires_mypy_type_ignore (value )
48
- else f"class { key } ({ value } ): # type: ignore\n pass\n "
49
- for key , value in spec_object .custom_types .items ()
50
- ]
44
+ def gen_new_type_definitions (custom_types : Dict [str , str ]) -> str :
45
+ return (
46
+ '\n \n ' .join (
47
+ [
48
+ f"class { key } ({ value } ):\n pass\n " if not requires_mypy_type_ignore (value )
49
+ else f"class { key } ({ value } ): # type: ignore\n pass\n "
50
+ for key , value in custom_types .items ()
51
+ ]
52
+ )
51
53
)
52
- )
54
+
55
+ new_type_definitions = gen_new_type_definitions (spec_object .custom_types )
56
+ preset_dep_new_type_definitions = gen_new_type_definitions (spec_object .preset_dep_custom_types )
53
57
54
58
# Collect builders with the reversed previous forks
55
59
# e.g. `[bellatrix, altair, phase0]` -> `[phase0, altair, bellatrix]`
@@ -115,7 +119,6 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
115
119
116
120
# Merge all constant objects
117
121
hardcoded_ssz_dep_constants = reduce (lambda obj , builder : {** obj , ** builder .hardcoded_ssz_dep_constants ()}, builders , {})
118
- hardcoded_custom_type_dep_constants = reduce (lambda obj , builder : {** obj , ** builder .hardcoded_custom_type_dep_constants (spec_object )}, builders , {})
119
122
hardcoded_func_dep_presets = reduce (lambda obj , builder : {** obj , ** builder .hardcoded_func_dep_presets (spec_object )}, builders , {})
120
123
# Concatenate all strings
121
124
imports = reduce (lambda txt , builder : (txt + "\n \n " + builder .imports (preset_name ) ).strip ("\n " ), builders , "" )
@@ -135,25 +138,26 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
135
138
filtered_hardcoded_func_dep_presets = {k : v for k , v in hardcoded_func_dep_presets .items () if k not in deprecate_presets }
136
139
137
140
constant_vars_spec = '# Constant vars\n ' + '\n ' .join (format_constant (k , v ) for k , v in spec_object .constant_vars .items ())
141
+ preset_dep_constant_vars_spec = '# Preset computed constants\n ' + '\n ' .join (format_constant (k , v ) for k , v in spec_object .preset_dep_constant_vars .items ())
138
142
preset_vars_spec = '# Preset vars\n ' + '\n ' .join (format_constant (k , v ) for k , v in spec_object .preset_vars .items ())
139
143
ordered_class_objects_spec = '\n \n \n ' .join (ordered_class_objects .values ())
140
144
ssz_dep_constants = '\n ' .join (map (lambda x : '%s = %s' % (x , hardcoded_ssz_dep_constants [x ]), hardcoded_ssz_dep_constants ))
141
145
ssz_dep_constants_verification = '\n ' .join (map (lambda x : 'assert %s == %s' % (x , spec_object .ssz_dep_constants [x ]), filtered_ssz_dep_constants ))
142
- custom_type_dep_constants = '\n ' .join (map (lambda x : '%s = %s' % (x , hardcoded_custom_type_dep_constants [x ]), hardcoded_custom_type_dep_constants ))
143
146
func_dep_presets_verification = '\n ' .join (map (lambda x : 'assert %s == %s # noqa: E501' % (x , spec_object .func_dep_presets [x ]), filtered_hardcoded_func_dep_presets ))
144
147
spec_strs = [
145
148
imports ,
146
149
preparations ,
147
150
f"fork = \' { fork } \' \n " ,
148
151
# The helper functions that some SSZ containers require. Need to be defined before `custom_type_dep_constants`
149
152
CONSTANT_DEP_SUNDRY_CONSTANTS_FUNCTIONS ,
150
- # The constants that some SSZ containers require. Need to be defined before `new_type_definitions`
151
- custom_type_dep_constants ,
152
153
# The constants that some SSZ containers require. Need to be defined before `constants_spec`
153
154
ssz_dep_constants ,
154
155
new_type_definitions ,
155
156
constant_vars_spec ,
157
+ # The presets that some SSZ types require. Need to be defined before `preset_dep_new_type_definitions`
156
158
preset_vars_spec ,
159
+ preset_dep_constant_vars_spec ,
160
+ preset_dep_new_type_definitions ,
157
161
config_spec ,
158
162
# Custom classes which are not required to be SSZ containers.
159
163
classes ,
@@ -194,7 +198,7 @@ def combine_dicts(old_dict: Dict[str, T], new_dict: Dict[str, T]) -> Dict[str, T
194
198
'uint8' , 'uint16' , 'uint32' , 'uint64' , 'uint128' , 'uint256' ,
195
199
'bytes' , 'byte' , 'ByteList' , 'ByteVector' ,
196
200
'Dict' , 'dict' , 'field' , 'ceillog2' , 'floorlog2' , 'Set' ,
197
- 'Optional' , 'Sequence' ,
201
+ 'Optional' , 'Sequence' , 'Tuple' ,
198
202
]
199
203
200
204
@@ -237,7 +241,9 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
237
241
protocols = combine_protocols (spec0 .protocols , spec1 .protocols )
238
242
functions = combine_dicts (spec0 .functions , spec1 .functions )
239
243
custom_types = combine_dicts (spec0 .custom_types , spec1 .custom_types )
244
+ preset_dep_custom_types = combine_dicts (spec0 .preset_dep_custom_types , spec1 .preset_dep_custom_types )
240
245
constant_vars = combine_dicts (spec0 .constant_vars , spec1 .constant_vars )
246
+ preset_dep_constant_vars = combine_dicts (spec0 .preset_dep_constant_vars , spec1 .preset_dep_constant_vars )
241
247
preset_vars = combine_dicts (spec0 .preset_vars , spec1 .preset_vars )
242
248
config_vars = combine_dicts (spec0 .config_vars , spec1 .config_vars )
243
249
ssz_dep_constants = combine_dicts (spec0 .ssz_dep_constants , spec1 .ssz_dep_constants )
@@ -248,7 +254,9 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
248
254
functions = functions ,
249
255
protocols = protocols ,
250
256
custom_types = custom_types ,
257
+ preset_dep_custom_types = preset_dep_custom_types ,
251
258
constant_vars = constant_vars ,
259
+ preset_dep_constant_vars = preset_dep_constant_vars ,
252
260
preset_vars = preset_vars ,
253
261
config_vars = config_vars ,
254
262
ssz_dep_constants = ssz_dep_constants ,
0 commit comments