Skip to content

Use type annotations to obviate the use of _or_ in function argument names #650

@rileyjmurray

Description

@rileyjmurray

While working on another PR I started to add type annotations to the run_long_sequence_gst function in drivers/longsequence.py. I found that argument names could be simplified considerably in the process. For example, the current signature is

def run_long_sequence_gst(data_filename_or_set, target_model_filename_or_object,
                          prep_fiducial_list_or_filename, meas_fiducial_list_or_filename,
                          germs_list_or_filename, max_lengths, gauge_opt_params=None,
                          advanced_options=None, comm=None, mem_limit=None,
                          output_pkl=None, verbosity=2, checkpoint=None, checkpoint_path=None,
                          disable_checkpointing=False,
                          simulator: Optional[ForwardSimulator.Castable]=None,
                          gauge_opt_suite_name: str = 'stdgaugeopt'):

while a type-annotated signature could be

FileName = str  # a type alias with clear semantic meaning

def run_long_sequence_gst(
        data: Union[FileName, DataSet], target_model: Union[FileName, _Model],
        prep_fiducials: Union[FileName, Sequence[Circuit]], 
        meas_fiducials: Union[FileName, Sequence[Circuit]],
        germs: Union[FileName, Sequence[Circuit]],
        max_lengths: Sequence[int], gauge_opt_params=None,
        advanced_options: Optional[dict[str, Any]]=None, comm=None, mem_limit=None,
        output_pkl=None, verbosity=2, checkpoint=None, checkpoint_path=None,
        disable_checkpointing=False,
        simulator: Optional[ForwardSimulator.Castable]=None,
        gauge_opt_suite_name: str = 'stdgaugeopt'):

I'm not going to propose these changes in my other PR, since that would complicate reviews. Making it note of this here so we can address it later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions