def __init__(self, segments, pos_marker=None, name: Optional[str] = None): # A cache variable for expandable self._is_expandable = None # Surrogate name option. self._surrogate_name = name if len(segments) == 0: raise RuntimeError( "Setting {0} with a zero length segment set. This shouldn't happen." .format(self.__class__)) if hasattr(segments, "matched_segments"): # Safely extract segments from a match self.segments = segments.matched_segments elif isinstance(segments, tuple): self.segments = segments elif isinstance(segments, list): self.segments = tuple(segments) else: raise TypeError( "Unexpected type passed to BaseSegment: {0}".format( type(segments))) if not pos_marker: # If no pos given, it's the pos of the first segment. if isinstance(segments, (tuple, list)): pos_marker = PositionMarker.from_child_markers( *(seg.pos_marker for seg in segments)) else: raise TypeError( "Unexpected type passed to BaseSegment: {0}".format( type(segments))) self.pos_marker: PositionMarker = pos_marker
def __init__(self, segments, pos_marker=None): if len(segments) == 0: raise RuntimeError( "Setting {0} with a zero length segment set. This shouldn't happen." .format(self.__class__)) if hasattr(segments, "matched_segments"): # Safely extract segments from a match self.segments = segments.matched_segments elif isinstance(segments, tuple): self.segments = segments elif isinstance(segments, list): self.segments = tuple(segments) else: raise TypeError( "Unexpected type passed to BaseSegment: {0}".format( type(segments))) if pos_marker: self.pos_marker = pos_marker else: # If no pos given, it's the pos of the first segment. if isinstance(segments, (tuple, list)): self.pos_marker = PositionMarker.from_child_markers( *(seg.pos_marker for seg in segments)) else: raise TypeError( "Unexpected type passed to BaseSegment: {0}".format( type(segments)))