Skip to content

type hint for SomeType*2 is list[SomeType] but could be Iterable[SomeType] #201

@KrisThielemans

Description

@KrisThielemans

We have

CoincidenceEvent: !record
  fields:
    # identifiers of the two detecting elements (see doc for DetectionBin)
    detectionBins: DetectionBin*2

This generates in types.py

class CoincidenceEvent:
    """All information about a coincidence event specified as indices (i.e. discretized)."""

    detection_bins: list[DetectionBin]

    def __init__(self, *,
        detection_bins: typing.Optional[list[DetectionBin]] = None,
        tof_idx: yardl.UInt32 = 0,
    ):
        self.detection_bins = detection_bins if detection_bins is not None else [DetectionBin() for _ in range(2)]

In my python code, I actually used a tuple as opposed to a list (I find that more intuitive for a list of 2 items), and everything works fine. However, pyright complains of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions