options: refactor Argument/pluginargument #5715
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This explicitly adds all keywords which are passed to
argparse.ArgumentParser.add_argument()to thepluginargumentdecorator (Argumentclass).It also turns all options except fornameinto mandatory keywords (which is technically a breaking change, but I don't think anyone with common sense has defined custom plugin arguments using positional args).The intention here is simplifying the parsing of the plugin module AST when building a plugins JSON file with all matchers and arguments (#4741), so Streamlink doesn't have to load all plugins at once. This is what I've been working on again in the past couple of days. It also improves type checking of all plugin arguments.
Opening this as a draft for now, because I don't want these changes to be included in the next release yet.
Unrelated to this PR, there's also one issue left with these changes which I will have to think about, namely the argument's
typeoption.The
typeoption is currently defined asCallable[[Any], Any] | None, but this makes it impossible to serialize when building the plugins JSON data.The data serializer needs to implement an import path lookup, so the
typeoption can reference the actual callable again, e.g.streamlink.utils.args.keyvalueorstreamlink.utils.times.hours_minutes_seconds. These are currently the two functions being used by Streamlink's plugins, but other callables like builtin ones need to be supported as well, likeintfor example. It will however restrict any custom functions defined in plugin modules, should this ever be required. Third party plugins won't be affected by the pluginargument serialization/deserialization, because those have to be loaded all at once beforehand anyway.