Skip to content

plugin: move match check to url setter, fix typing#6810

Merged
bastimeyer merged 1 commit intostreamlink:masterfrom
bastimeyer:plugin/matcher-and-match-check-in-url-setter
Feb 2, 2026
Merged

plugin: move match check to url setter, fix typing#6810
bastimeyer merged 1 commit intostreamlink:masterfrom
bastimeyer:plugin/matcher-and-match-check-in-url-setter

Conversation

@bastimeyer
Copy link
Copy Markdown
Member

Raise PluginError when the url attr is set and it doesn't match any of the plugin's matchers, not just once upon class initialization.

Remove None type from Plugin.matcher and Plugin.match: Since the input URL must always match, it is pointless to annotate these attributes as potentially being None. This causes lots of headaches in plugin implementations because it requires type-narrowing. Initialize them with None, so plugin tests without matchers don't have to call hasattr().


This fixes 120 typing errors in Streamlink's plugins, which are not checked by mypy by default, as this requires typing annotations (unless a custom config is set). ty checks this by default because of its Unknown type.

Raise `PluginError` when the `url` attr is set and it doesn't match
any of the plugin's matchers, not just once upon class initialization.

Remove `None` type from `Plugin.matcher` and `Plugin.match`:
Since the input URL must always match, it is pointless to annotate
these attributes as potentially being `None`. This causes lots of
headaches in plugin implementations because it requires type-narrowing.
Initialize them with `None`, so plugin tests without matchers
don't have to call `hasattr()`.
@bastimeyer
Copy link
Copy Markdown
Member Author

These plugins update the url attribute dynamically:

$ git grep -nFE 'self.url = ' -- src/streamlink/plugins
src/streamlink/plugins/atresplayer.py:30:        self.url = update_scheme("https://", f"{self.url.rstrip('/')}/")
src/streamlink/plugins/bbciplayer.py:101:        self.url = urlunparse(urlparse(self.url)._replace(scheme="https"))
src/streamlink/plugins/dogan.py:108:            self.url = default_service_url
src/streamlink/plugins/filmon.py:189:            self.url = urlunparse(parsed._replace(path=parsed.path.replace("/channel/", "/tv/")))
src/streamlink/plugins/mangomolo.py:42:        self.url = update_scheme("https://", player_url)
src/streamlink/plugins/okru.py:70:        self.url = url
src/streamlink/plugins/oneplusone.py:68:        self.url = url
src/streamlink/plugins/steam.py:230:            self.url = self._watch_broadcast_url.format(steamid=steamid)
src/streamlink/plugins/streann.py:151:            self.url = iframes[0].attrib.get("src")
src/streamlink/plugins/twitcasting.py:180:        self.url = update_qsd(url, params or {})
src/streamlink/plugins/vk.py:62:            self.url = f"{parsed_url.scheme}://{parsed_url.netloc}/{true_path}"
src/streamlink/plugins/vk.py:69:            self.url = self.session.http.get(
src/streamlink/plugins/youtube.py:91:            self.url = urlunparse(parsed._replace(scheme="https", netloc="www.youtube.com"))
src/streamlink/plugins/youtube.py:93:            self.url = self._url_canonical.format(video_id=self.match["video_id"])
src/streamlink/plugins/youtube.py:95:            self.url = self._url_canonical.format(video_id=self.match["video_id"])
src/streamlink/plugins/youtube.py:97:            self.url = self._url_channelid_live.format(channel_id=self.match["live"])
src/streamlink/plugins/youtube.py:99:            self.url = urlunparse(parsed._replace(scheme="https"))
src/streamlink/plugins/youtube.py:379:            self.url = self._url_canonical.format(video_id=video_id)

@bastimeyer bastimeyer merged commit 9644328 into streamlink:master Feb 2, 2026
25 checks passed
@bastimeyer bastimeyer deleted the plugin/matcher-and-match-check-in-url-setter branch February 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant