1212from collections import defaultdict
1313from collections .abc import Callable
1414from enum import Flag , auto
15- from typing import Any , TextIO , Union , cast
15+ from typing import Any , TextIO , cast
1616
1717from ..utilities import castep_res as REs
1818from ..utilities .castep_res import gen_table_re , get_numbers , labelled_floats
@@ -1683,7 +1683,11 @@ def _process_unit_cell(block: Block) -> CellInfo:
16831683 else :
16841684 prop .append (float (numbers [0 ]))
16851685
1686- cell .update ({name : val for val , name in zip (prop , ("volume" , "density_amu" , "density_g" ))})
1686+ cell .update ({name : val for val , name in zip (
1687+ prop ,
1688+ ("volume" , "density_amu" , "density_g" ),
1689+ strict = False ,
1690+ )})
16871691
16881692 return cell
16891693
@@ -1812,7 +1816,7 @@ def _process_initial_spins(block: Block) -> dict[AtomIndex, InitialSpin]:
18121816 ind = atreg_to_index (val )
18131817 fix_data_types (val , {"spin" : float , "magmom" : float })
18141818 val ["fix" ] = val ["fix" ] == "T"
1815- accum [ind ] = cast (dict [str , Union [ float , bool ] ], val )
1819+ accum [ind ] = cast (dict [str , float | bool ], val )
18161820 return accum
18171821
18181822
@@ -2201,8 +2205,9 @@ def _process_dynamical_matrix(block: Block) -> tuple[tuple[complex, ...], ...]:
22012205 imag_part = [numbers [2 :] for line in block if (numbers := get_numbers (line ))]
22022206
22032207 return tuple (
2204- tuple (complex (float (real ), float (imag )) for real , imag in zip (real_row , imag_row ))
2205- for real_row , imag_row in zip (real_part , imag_part )
2208+ tuple (complex (float (real ), float (imag ))
2209+ for real , imag in zip (real_row , imag_row , strict = True ))
2210+ for real_row , imag_row in zip (real_part , imag_part , strict = True )
22062211 )
22072212
22082213
@@ -2302,7 +2307,11 @@ def _process_dftd(block: Block) -> dict[str, Any]:
23022307def _process_occupancies (block : Block ) -> list [Occupancies ]:
23032308 label = ("band" , "eigenvalue" , "occupancy" )
23042309
2305- accum = [dict (zip (label , numbers )) for line in block if (numbers := get_numbers (line ))]
2310+ accum = [
2311+ dict (zip (label , numbers , strict = True ))
2312+ for line in block
2313+ if (numbers := get_numbers (line ))
2314+ ]
23062315 for elem in accum :
23072316 fix_data_types (elem , {"band" : int ,
23082317 "eigenvalue" : float ,
@@ -2369,7 +2378,7 @@ def _process_phonon(block: Block, logger: Logger) -> list[QData]:
23692378 head , tail = char_line .split ("|" )
23702379 _ , rep , * name , mul = head .split ()
23712380 * vals , _ = tail .split ()
2372- char .append ({"chars" : tuple (zip (headers , map (int , vals ))),
2381+ char .append ({"chars" : tuple (zip (headers , map (int , vals ), strict = False )),
23732382 "mul" : int (mul ),
23742383 "rep" : rep ,
23752384 "name" : name })
@@ -2429,9 +2438,13 @@ def _process_pair_params(block_in: Block) -> dict[str, dict[str, dict | str]]:
24292438 if lab not in accum [typ ]:
24302439 accum [typ ][lab ] = {}
24312440
2432- accum [typ ][lab ].update (zip (labels ,
2433- to_type (match ["params" ].split (),
2434- float )))
2441+ accum [typ ][lab ].update (
2442+ zip (
2443+ labels ,
2444+ to_type (match ["params" ].split (), float ),
2445+ strict = True ,
2446+ ),
2447+ )
24352448
24362449 elif match := REs .PAIR_POT_RES ["two_body_one_spec" ].match (blk_line ):
24372450 labels = ((match ["spec" ],),)
@@ -2454,7 +2467,7 @@ def _process_pair_params(block_in: Block) -> dict[str, dict[str, dict | str]]:
24542467
24552468 accum [typ ][lab ].update (zip (labels ,
24562469 to_type (match ["params" ].split (),
2457- float )))
2470+ float ), strict = False ))
24582471
24592472 # Globals
24602473 elif match := REs .PAIR_POT_RES ["three_body_val" ].match (line ):
@@ -2479,7 +2492,7 @@ def _process_geom_table(block: Block) -> GeomTable:
24792492 fix_data_types (val , dict .fromkeys (("lambda" , "fdelta" , "enthalpy" ), float ))
24802493
24812494 key = normalise_string (val .pop ("step" ))
2482- accum [key ] = cast (dict [str , Union [ bool , float ] ], val )
2495+ accum [key ] = cast (dict [str , bool | float ], val )
24832496
24842497 elif match := REs .GEOMOPT_TABLE_RE .match (line ):
24852498 val = match .groupdict ()
@@ -2488,7 +2501,7 @@ def _process_geom_table(block: Block) -> GeomTable:
24882501 val ["converged" ] = val ["converged" ] == "Yes"
24892502
24902503 key = normalise_key (val .pop ("parameter" ))
2491- accum [key ] = cast (dict [str , Union [ bool , float ] ], val )
2504+ accum [key ] = cast (dict [str , bool | float ], val )
24922505
24932506 return accum
24942507
@@ -2523,7 +2536,7 @@ def _process_elastic_properties(block: Block) -> ElasticProperties:
25232536 for line in block :
25242537 if "::" in line :
25252538 key = line .split ("::" )[0 ]
2526- val = cast (Union [ ThreeVector , SixVector ] , to_type (get_numbers (line ), float ))
2539+ val = cast (ThreeVector | SixVector , to_type (get_numbers (line ), float ))
25272540
25282541 if len (val ) == 1 :
25292542 val = val [0 ]
@@ -2543,7 +2556,7 @@ def _process_elastic_properties(block: Block) -> ElasticProperties:
25432556def _process_internal_constraints (block : TextIO ) -> list [InternalConstraints ]:
25442557
25452558 # Skip table headers
2546- for _ in zip (range (3 ), block ):
2559+ for _ in zip (range (3 ), block , strict = False ):
25472560 pass
25482561
25492562 accum = []
0 commit comments