-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add function/decorator checks for variable-format/resolution clips #37
Add function/decorator checks for variable-format/resolution clips #37
Conversation
2318bd2
to
286b102
Compare
286b102
to
9f334e3
Compare
Is there a way to get mypy to recognize this? Right now it doesn't seem smart enough to follow the Edit: potentially something like class ConstantFormatNode(vs.VideoNode):
format: vs.Format
def disallow_variable_format(function: Callable[..., R]) -> Callable[..., R]:
"""
Function decorator that raises an exception if the input clip has a variable format.
"""
def _check(clip: vs.VideoNode, *args: Any, **kwargs: Any) -> R:
if is_variable(clip, format=True):
raise ValueError('Variable-format clips not supported.')
clip.__class__ = ConstantFormatNode
return function(clip, *args, **kwargs)
return _check and making the unwrapped functions take |
@heicrd yes. But it seems that all type-checkers hate Decorators and Descriptors. |
This can all be squashed into one commit with the PR title and reference #. |
Should we bump the version number in this update? This technically changes the exposed API by adding three new functions. I recommend tagging ee49d9d as |
So, I've completely satisfied mypy's issues on vsutil's side here: https://www.diffchecker.com/tGKtXhE5 |
I’m against doing that. Having the casts inside the decorators is fine, but adding them everywhere just to make a dysfunctional typechecker happy is not what I want. We shouldn’t make code more complicated just to please the IDE or some third-party tool. In general, we might consider making some of these functions work with variable formats (e.g. I don’t see a reason why As for the tags, I’ve tagged the commit you suggested as 0.3.0, and I agree with tagging this as 0.4.0. I’ll do that after merge. |
Yeah you can just cast inside the decorator and change the function signature to
vsutil is already beyond this point with using typehints and unit tests in the first place imo. i don't think it's a good idea either way to try and draw contributors who have actually zero programming experience |
I’ll make a more coherent response later but wanted to say that casting inside the decorator doesn’t solve mypy’s problem. It also creates another problem where another script calling get_subsampling(clip_VideoNode) is an error because isinstance(clip_VideoNode, _ConstantFormatNode) is False. mypy isn’t smart enough to know what to do with a changed signature via the decorator and casting inside the decorator means losing the ability to use the decorated functions with normal VideoNodes. |
@OrangeChannel I’m still kind of waiting for that. |
Oh I think I just explained the problem with typechecking the decorators in Light’s discord. There’s not much we can do here that wouldn’t be super over-engineered so as far as I’m concerned, the PR is ready to merge. |
There’s a few open issues in mypy’s repo that might address this stuff in the future but for now the casting and stuff isn’t worth it. |
This prevents us having to write the same
ValueError
for every function that requires a clip to have a format because it tries to access theclip.format
's attributes.