@@ -23,8 +23,19 @@ def collect_prev_forks(fork: str) -> list[str]:
2323
2424
2525def  requires_mypy_type_ignore (value : str ) ->  bool :
26-     return  value .startswith ("ByteVector" ) or  (
27-         value .startswith ("Vector" ) and  any (k  in  value  for  k  in  ["ceillog2" , "floorlog2" ])
26+     return  (
27+         value .startswith ("Bitlist" )
28+         or  value .startswith ("ByteVector" )
29+         or  (value .startswith ("List" ) and  not  re .match (r"^List\[\w+,\s*\w+\]$" , value ))
30+         or  (value .startswith ("Vector" ) and  any (k  in  value  for  k  in  ["ceillog2" , "floorlog2" ]))
31+     )
32+ 
33+ 
34+ def  gen_new_type_definition (name : str , value : str ) ->  str :
35+     return  (
36+         f"class { name }  ({ value }  ):\n     pass" 
37+         if  not  requires_mypy_type_ignore (value )
38+         else  f"class { name }  (\n     { value }    # type: ignore\n ):\n     pass" 
2839    )
2940
3041
@@ -41,19 +52,11 @@ def objects_to_spec(
4152    """ 
4253
4354    def  gen_new_type_definitions (custom_types : dict [str , str ]) ->  str :
44-         return  "\n \n " .join (
45-             [
46-                 (
47-                     f"class { key }  ({ value }  ):\n     pass\n " 
48-                     if  not  requires_mypy_type_ignore (value )
49-                     else  f"class { key }  ({ value }  ):  # type: ignore\n     pass\n " 
50-                 )
51-                 for  key , value  in  custom_types .items ()
52-             ]
55+         return  "\n \n \n " .join (
56+             [gen_new_type_definition (key , value ) for  key , value  in  custom_types .items ()]
5357        )
5458
5559    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 )
5760
5861    # Collect builders with the reversed previous forks 
5962    # e.g. `[bellatrix, altair, phase0]` -> `[phase0, altair, bellatrix]` 
@@ -224,10 +227,9 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
224227        ssz_dep_constants ,
225228        new_type_definitions ,
226229        constant_vars_spec ,
227-         # The presets that some SSZ types require. Need to be defined before `preset_dep_new_type_definitions`  
230+         # The presets that some SSZ types require. 
228231        preset_vars_spec ,
229232        preset_dep_constant_vars_spec ,
230-         preset_dep_new_type_definitions ,
231233        config_spec ,
232234        # Custom classes which are not required to be SSZ containers. 
233235        classes ,
@@ -267,8 +269,6 @@ def combine_dicts(old_dict: dict[str, T], new_dict: dict[str, T]) -> dict[str, T
267269    "bit" ,
268270    "Bitlist" ,
269271    "Bitvector" ,
270-     "BLSPubkey" ,
271-     "BLSSignature" ,
272272    "boolean" ,
273273    "byte" ,
274274    "ByteList" ,
@@ -292,6 +292,8 @@ def combine_dicts(old_dict: dict[str, T], new_dict: dict[str, T]) -> dict[str, T
292292    "floorlog2" ,
293293    "List" ,
294294    "Optional" ,
295+     "ProgressiveBitlist" ,
296+     "ProgressiveList" ,
295297    "Sequence" ,
296298    "Set" ,
297299    "Tuple" ,
@@ -312,10 +314,14 @@ def dependency_order_class_objects(objects: dict[str, str], custom_types: dict[s
312314    items  =  list (objects .items ())
313315    for  key , value  in  items :
314316        dependencies  =  []
315-         for  line  in  value .split ("\n " ):
316-             if  not  re .match (r"\s+\w+: .+" , line ):
317+         for  i , line  in  enumerate (value .split ("\n " )):
318+             if  i  ==  0 :
319+                 match  =  re .match (r".+\((.+)\):" , line )
320+             else :
321+                 match  =  re .match (r"\s+\w+: (.+)" , line )
322+             if  not  match :
317323                continue   # skip whitespace etc. 
318-             line  =  line [ line . index ( ":" )  +   1  :]   # strip of field name 
324+             line  =  match . group ( 1 ) 
319325            if  "#"  in  line :
320326                line  =  line [: line .index ("#" )]  # strip of comment 
321327            dependencies .extend (
@@ -349,9 +355,6 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
349355    protocols  =  combine_protocols (spec0 .protocols , spec1 .protocols )
350356    functions  =  combine_dicts (spec0 .functions , spec1 .functions )
351357    custom_types  =  combine_dicts (spec0 .custom_types , spec1 .custom_types )
352-     preset_dep_custom_types  =  combine_dicts (
353-         spec0 .preset_dep_custom_types , spec1 .preset_dep_custom_types 
354-     )
355358    constant_vars  =  combine_dicts (spec0 .constant_vars , spec1 .constant_vars )
356359    preset_dep_constant_vars  =  combine_dicts (
357360        spec0 .preset_dep_constant_vars , spec1 .preset_dep_constant_vars 
@@ -366,7 +369,6 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
366369        functions = functions ,
367370        protocols = protocols ,
368371        custom_types = custom_types ,
369-         preset_dep_custom_types = preset_dep_custom_types ,
370372        constant_vars = constant_vars ,
371373        preset_dep_constant_vars = preset_dep_constant_vars ,
372374        preset_vars = preset_vars ,
@@ -378,6 +380,41 @@ def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
378380    )
379381
380382
383+ def  finalized_spec_object (spec_object : SpecObject ) ->  SpecObject :
384+     all_config_dependencies  =  {
385+         vardef .type_name  or  vardef .type_hint 
386+         for  vardef  in  (
387+             spec_object .constant_vars 
388+             |  spec_object .preset_dep_constant_vars 
389+             |  spec_object .preset_vars 
390+             |  spec_object .config_vars 
391+         ).values ()
392+         if  (vardef .type_name  or  vardef .type_hint ) is  not   None 
393+     }
394+ 
395+     custom_types  =  {}
396+     ssz_objects  =  spec_object .ssz_objects 
397+     for  name , value  in  spec_object .custom_types .items ():
398+         if  any (k  in  name  for  k  in  all_config_dependencies ):
399+             custom_types [name ] =  value 
400+         else :
401+             ssz_objects [name ] =  gen_new_type_definition (name , value )
402+ 
403+     return  SpecObject (
404+         functions = spec_object .functions ,
405+         protocols = spec_object .protocols ,
406+         custom_types = custom_types ,
407+         constant_vars = spec_object .constant_vars ,
408+         preset_dep_constant_vars = spec_object .preset_dep_constant_vars ,
409+         preset_vars = spec_object .preset_vars ,
410+         config_vars = spec_object .config_vars ,
411+         ssz_dep_constants = spec_object .ssz_dep_constants ,
412+         func_dep_presets = spec_object .func_dep_presets ,
413+         ssz_objects = ssz_objects ,
414+         dataclasses = spec_object .dataclasses ,
415+     )
416+ 
417+ 
381418def  parse_config_vars (conf : dict [str , str ]) ->  dict [str , str  |  list [dict [str , str ]]]:
382419    """ 
383420    Parses a dict of basic str/int/list types into a dict for insertion into the spec code. 
0 commit comments