Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stubs for m3u8 #12683

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"stubs/jsonschema",
"stubs/jwcrypto",
"stubs/ldap3",
"stubs/m3u8",
"stubs/Markdown",
"stubs/mysqlclient",
"stubs/netaddr/netaddr/core.pyi",
Expand Down
17 changes: 17 additions & 0 deletions stubs/m3u8/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# type check only
m3u8.httpclient.HTTPSHandler.__new__
# internal functions and attributes
m3u8.M3U8.simple_attributes
m3u8.model.M3U8.simple_attributes
m3u8.model.denormalize_attribute
m3u8.model.find_key
m3u8.model.number_to_string
m3u8.model.quoted
m3u8.parser.cast_date_time
m3u8.parser.format_date_time
m3u8.parser.get_segment_custom_value
m3u8.parser.normalize_attribute
m3u8.parser.remove_quotes
m3u8.parser.remove_quotes_parser
m3u8.parser.save_segment_custom_value
m3u8.parser.string_to_lines
2 changes: 2 additions & 0 deletions stubs/m3u8/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "6.0.*"
upstream_repository = "https://github.com/globocom/m3u8"
74 changes: 74 additions & 0 deletions stubs/m3u8/m3u8/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from _typeshed import Incomplete
from collections.abc import Callable, Mapping
from typing import Any
from typing_extensions import TypeAlias

from m3u8.httpclient import _HTTPClientProtocol
from m3u8.model import (
M3U8,
ContentSteering,
DateRange,
DateRangeList,
IFramePlaylist,
ImagePlaylist,
Key,
Media,
MediaList,
PartialSegment,
PartialSegmentList,
PartInformation,
Playlist,
PlaylistList,
PreloadHint,
RenditionReport,
RenditionReportList,
Segment,
SegmentList,
ServerControl,
Skip,
Start,
Tiles,
)
from m3u8.parser import ParseError, parse

__all__ = (
"M3U8",
"Segment",
"SegmentList",
"PartialSegment",
"PartialSegmentList",
"Key",
"Playlist",
"IFramePlaylist",
"Media",
"MediaList",
"PlaylistList",
"Start",
"RenditionReport",
"RenditionReportList",
"ServerControl",
"Skip",
"PartInformation",
"PreloadHint",
"DateRange",
"DateRangeList",
"ContentSteering",
"ImagePlaylist",
"Tiles",
"loads",
"load",
"parse",
"ParseError",
)

_CustomTagsParser: TypeAlias = Callable[[str, int, dict[str, Any], dict[str, Any]], object]

def loads(content: str, uri: str | None = None, custom_tags_parser: _CustomTagsParser | None = None) -> M3U8: ...
def load(
uri: str,
timeout: Incomplete | None = None,
headers: Mapping[str, Any] = {},
custom_tags_parser: _CustomTagsParser | None = None,
http_client: _HTTPClientProtocol = ...,
verify_ssl: bool = True,
) -> M3U8: ...
19 changes: 19 additions & 0 deletions stubs/m3u8/m3u8/httpclient.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import urllib.request
from typing import Any, Protocol, type_check_only

@type_check_only
class _HTTPClientProtocol(Protocol): # noqa: Y046
def download(
self, uri: str, timeout: float | None = None, headers: dict[str, Any] = {}, verify_ssl: bool = True
) -> tuple[str, str]: ...

class DefaultHTTPClient:
proxies: dict[str, str] | None

def __init__(self, proxies: dict[str, str] | None = None) -> None: ...
def download(
self, uri: str, timeout: float | None = None, headers: dict[str, Any] = {}, verify_ssl: bool = True
) -> tuple[str, str]: ...

class HTTPSHandler:
def __new__(cls, verify_ssl: bool = True) -> urllib.request.HTTPSHandler: ... # type: ignore
27 changes: 27 additions & 0 deletions stubs/m3u8/m3u8/mixins.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# mypy: disable-error-code="attr-defined"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary. In general, we prefer # type: ignore[attr-defined] on the lines that this actually affects.


from abc import ABCMeta
from collections.abc import Iterable
from typing import Protocol, TypeVar

_T = TypeVar("_T")

class BasePathMixin(Protocol):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is not a protocol at runtime, it shouldn't be a protocol here either.

uri: str | None
@property
def absolute_uri(self) -> str: ...
@property
def base_path(self) -> str: ...
@base_path.setter
def base_path(self, newbase_path: str) -> None: ...
def get_path_from_uri(self) -> str: ...

class GroupedBasePathMixin(Iterable[_T], metaclass=ABCMeta):
@property
def base_uri(self) -> str: ...
@base_uri.setter
def base_uri(self, __new_url: str, /) -> None: ...
@property
def base_path(self) -> str: ...
@base_path.setter
def base_path(self, __new_url: str, /) -> None: ...
Loading