Skip to content

Commit ce50cca

Browse files
committed
Add typing for all lists
1 parent 83cdc26 commit ce50cca

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

m3u8/model.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# license that can be found in the LICENSE file.
44
import decimal
55
import os
6+
from typing import TypeVar
67

78
from m3u8.mixins import BasePathMixin, GroupedBasePathMixin
89
from m3u8.parser import format_date_time, parse
@@ -449,7 +450,10 @@ def _create_sub_directories(self, filename):
449450
os.makedirs(basename, exist_ok=True)
450451

451452

452-
class TagList(list):
453+
T = TypeVar("T")
454+
455+
456+
class TagList(list[T]):
453457
def __str__(self):
454458
output = [str(tag) for tag in self]
455459
return "\n".join(output)
@@ -712,7 +716,7 @@ def base_uri(self, newbase_uri):
712716
self.init_section.base_uri = newbase_uri
713717

714718

715-
class SegmentList(list, GroupedBasePathMixin):
719+
class SegmentList(list[Segment], GroupedBasePathMixin):
716720
def dumps(self, timespec="milliseconds", infspec="auto"):
717721
output = []
718722
last_segment = None
@@ -827,7 +831,7 @@ def __str__(self):
827831
return self.dumps(None)
828832

829833

830-
class PartialSegmentList(list, GroupedBasePathMixin):
834+
class PartialSegmentList(list[PartialSegment], GroupedBasePathMixin):
831835
def __str__(self):
832836
output = [str(part) for part in self]
833837
return "\n".join(output)
@@ -1015,7 +1019,7 @@ def __str__(self):
10151019
return "#EXT-X-STREAM-INF:" + ",".join(stream_inf) + "\n" + self.uri
10161020

10171021

1018-
class PlaylistList(TagList, GroupedBasePathMixin):
1022+
class PlaylistList(TagList[Playlist], GroupedBasePathMixin):
10191023
pass
10201024

10211025

@@ -1270,7 +1274,7 @@ def __str__(self):
12701274
return self.dumps()
12711275

12721276

1273-
class MediaList(TagList, GroupedBasePathMixin):
1277+
class MediaList(TagList[Media], GroupedBasePathMixin):
12741278
@property
12751279
def uri(self):
12761280
return [media.uri for media in self]
@@ -1310,7 +1314,7 @@ def __str__(self):
13101314
return self.dumps()
13111315

13121316

1313-
class RenditionReportList(list, GroupedBasePathMixin):
1317+
class RenditionReportList(list[RenditionReport], GroupedBasePathMixin):
13141318
def __str__(self):
13151319
output = [str(report) for report in self]
13161320
return "\n".join(output)
@@ -1439,7 +1443,7 @@ def __str__(self):
14391443
return self.dumps()
14401444

14411445

1442-
class SessionDataList(TagList):
1446+
class SessionDataList(TagList[SessionData]):
14431447
pass
14441448

14451449

@@ -1498,7 +1502,7 @@ def __str__(self):
14981502
return self.dumps()
14991503

15001504

1501-
class DateRangeList(TagList):
1505+
class DateRangeList(TagList[DateRange]):
15021506
pass
15031507

15041508

0 commit comments

Comments
 (0)