[BUGFIX] Fix output sanitization type checking (#1467)

In the inspection output, we check function's return types via issubclass to see if an optimization can be made. Guard against this check in case the return type isn't a class -- it could be a Union[..., ...] from a conditional.
This commit is contained in:
Jesse Bannon 2026-05-10 09:19:27 -07:00 committed by GitHub
parent b195f37412
commit 4421c4eede
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -7,8 +7,11 @@ from typing import Callable, List, Optional, Type, TypeVar, Union, get_origin
from ytdl_sub.script.types.resolvable import (
Argument,
Boolean,
BuiltInFunctionType,
Float,
FutureResolvable,
Integer,
Lambda,
LambdaReduce,
LambdaThree,
@ -248,6 +251,17 @@ class FunctionSpec:
return l_type
return None
def has_sanitized_output(self) -> bool:
"""
Returns
-------
If this function were to be sanitized, whether it's redundant or not based on its
output
"""
return inspect.isclass(self.return_type) and issubclass(
self.return_type, (Integer, Float, Boolean)
)
@classmethod
def _to_human_readable_name(cls, python_type: Type[NamedType] | Type[Union[NamedType]]) -> str:
if is_optional(python_type):

View file

@ -146,8 +146,7 @@ class ScriptUtils:
elif isinstance(sub_arg, String):
output += CustomFunctions.sanitize(sub_arg).native
elif isinstance(sub_arg, BuiltInFunction) and (
issubclass(sub_arg.function_spec.return_type, (Integer, Float, Boolean))
or sub_arg.name == "pad_zero"
sub_arg.function_spec.has_sanitized_output() or sub_arg.name == "pad_zero"
):
# If we know the function's output is sanitized, let's not wrap it
output += cls._to_script_code(sub_arg, top_level=True)