Skip to content

Conversation

@bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Nov 27, 2024

This makes the options arguments of both the Streamlink session class and the Plugin class more consistent. The former currently doesn't allow passing an Options object as the options argument, while the latter doesn't allow dicts and always requires an Options object.

The reason for these inconsistencies is that the Streamlink session defines a set of default values and key-value mappings, so passing an Options object didn't make sense when it was implemented. The Plugin options argument was implemented when the Plugin.bind() nonsense was removed and Plugin.options were turned from class attributes to instance attributes (5.0.0 - #5033), so regular dicts were never considered as plugin options arguments.

A side-effect of these changes however is that plugin options now don't have default values anymore, because the argument is always merged into an empty Options object. I'm not fully sure if this is actually relevant here in the plugin API. I'll have to think about it, because I don't want to break any downstream stuff. Opening this as a draft for now because of that.

Custom plugin options are now set as default values on the plugin's options object, copied from the passed dict or Options object.

Instead of using an internal `options` dict attribute,
make `Options` inherit from `dict[str, Any]` directly,
so both `Options` and `dict`s can be merged in `update()`.

Update tests and also explicitly override the typing annotations
of `get()` (no default value) and `update()` (only single mapping arg).
@bastimeyer bastimeyer force-pushed the options/inherit-from-dict branch from 5eecceb to 61f1502 Compare December 28, 2024 15:13
@bastimeyer bastimeyer marked this pull request as ready for review December 28, 2024 15:13
@bastimeyer bastimeyer merged commit 68cea62 into streamlink:master Dec 28, 2024
23 checks passed
@bastimeyer bastimeyer deleted the options/inherit-from-dict branch December 28, 2024 15:17
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