Skip to content

plugin: fix shared matchers and arguments in inherited plugins #6297

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

Merged

Conversation

bastimeyer
Copy link
Member

This fixes accidentally shared matchers and arguments references in plugin classes which inherit from existing plugin classes.

It's not really a problematic issue, as it's very unlikely that the ancestor plugin class is used in a Streamlink session when it's already overridden by a plugin subclass in the same session, but it should still be fixed.

These changes unfortunately make the Plugin API docs look a bit weird.


Fixing this also made me realize that we never deprecated the old arguments = Arguments(...) definition style in plugin classes. The docs tell the user to always use the plugin decorators, but this is not enforced, hence why there's even a test case for the old plugin arguments definition. The matchers definition is theoretically also possible this way. This doesn't affect Streamlink's own plugins though, so it's probably not worth deprecating or directly removing this.

Another thing that should probably also be changed and cleaned up in the future is how the Matchers and Arguments are defined. Argument and Arguments are part of the options module, because they are tied to the Options class, while the Matcher and Matchers classes are part of the plugin module (and thus the streamlink.plugin package). Everything's actually only related to plugins, so the options module shouldn't be in its current place in the root streamlink package. streamlink.plugin already re-exports everything from the options module.

- Add metaclass for `Plugin` and set the `matchers` class attribute
  when a subclass is created, rather than checking if it's not `None`
  in the `pluginmatcher` decorator
- Refactor `Matchers` and its base class, to allow passing `Matcher`
  objects to its constructor
- Rename `Matchers.register()` to `Matchers.add()`, so it's consistent
  with `Arguments.add()`
- Update tests
- Set the `arguments` class attribute when a subclass is created,
  rather than checking if it's not `None` in the `pluginargument`
  decorator
- Update tests
@bastimeyer bastimeyer force-pushed the plugin/fix-shared-matchers-arguments branch from dc31ead to 67d709a Compare November 17, 2024 17:53
@bastimeyer bastimeyer merged commit 0b3b22f into streamlink:master Nov 17, 2024
23 checks passed
@bastimeyer bastimeyer deleted the plugin/fix-shared-matchers-arguments branch November 17, 2024 17:57
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