Commit Graph

12 Commits

Author SHA1 Message Date
bastimeyer 45e515eb5a session/plugin: fix DeprecationWarning stacklevel 2023-03-24 09:41:23 -07:00
bastimeyer 5e6f03c3cd chore: add "B" rules to ruff config 2023-03-24 09:41:23 -07:00
bastimeyer 85ea235d13 chore: add "A" rules to ruff config 2023-02-20 14:10:06 -08:00
bastimeyer faab9200c7 chore: add "I" and "TID" rules to ruff config 2023-02-09 10:26:50 -08:00
bastimeyer fe9be00832 chore: ignore coverage in TYPE_CHECKING blocks 2023-01-14 07:47:08 +01:00
bastimeyer c211e5866e plugin.api.validate: deprecate text alias
- Deprecate text alias and raise StreamlinkDeprecationWarning on access
- Add deprecation to docs
- Replace validate.text with str in remaining plugins
- Update test
2023-01-13 11:27:11 -08:00
bastimeyer b7b0353b51 plugin.api.validate: refactor ValidationError
- Remove `ValidationError` from package's `__init__` module.
  It was never meant to be a public export. Update tests accordingly.
- Remove `context` argument from `ValidationError` and use the
  exception's `__cause__` property instead, and add the "raise from"
  statements to schema validations and validators where a context was
  set previously. Explicitly "raise from None" where a context should
  be suppressed.
- Fix unneeded type cast when printing `ValidationError` template string
- Fix length comparison in `length` validator
2022-08-27 13:56:29 +02:00
bastimeyer cd3645a033 plugin.api.validate: add RegexSchema 2022-08-05 12:27:46 -07:00
bastimeyer cb56e063c9 plugin.api.validate: add NoneOrAllSchema
This helps avoiding the validation pattern
```py
validate.any(None, validate.all(...))
```

and is useful for `re.Pattern` and `xml_xpath_string` validations,
where the validation result can be `None` and is usually used for
gracefully returning no validation results instead of raising an error.
2022-08-04 11:06:32 -07:00
bastimeyer 047bc8e0c9 plugin.api.validate: add ListSchema
In contrast to the `list` instance validation where sequence subsets
get validated, the `ListSchema` validates that the input list has the
same length and that all list items validate successfully according to
the defined schemas.
2022-08-04 11:06:32 -07:00
bastimeyer 3d44da082b plugin.api.validate: implement ValidationError
- Implement `ValidationError`
  - Inherit from `ValueError` to preserve backwards compatiblity
  - Allow collecting multiple errors (AnySchema)
  - Keep an error stack of parent `ValidationError`s or other exceptions
  - Format error stack when converting error to string
- Raise `ValidationError` instead of `ValueError`
  - Add error contexts where it makes sense
  - Add schema names to error instances
- Add and update tests
2022-05-08 09:21:19 +02:00
bastimeyer 120c103023 plugin.api.validate: turn module into package
Turn module into package with multiple logical sub-modules:
- Define a public interface in the package's `__init__` module
- Split validation schemas, validators and validate logic
  - schemas: classes which register attributes used by their
    respective `validate` implementations
  - validators: functions which can internally call `validate`
    and which return something that can be validated
  - validate: singledispatch functions which implement the validation
    logic for schemas and various other types
- Rename validation schemas for better internal references
- Rename singledispatch methods

Other clean-up work:
- Update comments and fix grammar
- Add type annotations
- Use f-strings
- Use `str` instead of the `text` alias
- Simplify some code blocks
- Rearrange classes and functions
- Rephrase certain error messages
- Add a few more tests for better code coverage
2022-05-08 09:21:19 +02:00