[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:
parent
b195f37412
commit
4421c4eede
2 changed files with 15 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue