lint begins

This commit is contained in:
Jesse Bannon 2023-12-13 14:20:20 -08:00
parent 7875139050
commit c38ac2da4d
16 changed files with 15 additions and 44 deletions

View file

@ -1,4 +1,3 @@
import copy
from typing import Any
from typing import Dict
from typing import Optional

View file

@ -151,8 +151,9 @@ class PluginMapping:
return [
plugin for plugin in ordered_plugins if not cls._is_modified_after_split(plugin)
]
else: # before_split is False
return [plugin for plugin in ordered_plugins if cls._is_modified_after_split(plugin)]
# before_split is False
return [plugin for plugin in ordered_plugins if cls._is_modified_after_split(plugin)]
@classmethod
def plugins(cls) -> List[str]:

View file

@ -22,7 +22,7 @@ v: VariableDefinitions = VARIABLES
YTDL_SUB_ENTRY_VARIABLES_KWARG_KEY: str = "ytdl_sub_entry_variables"
TType = TypeVar("TType")
TypeT = TypeVar("TypeT")
class Entry(BaseEntry, Scriptable):
@ -50,11 +50,11 @@ class Entry(BaseEntry, Scriptable):
self._add_entry_kwargs_to_script()
return self
def get(self, variable: Variable, expected_type: Type[TType]) -> TType:
def get(self, variable: Variable, expected_type: Type[TypeT]) -> TypeT:
out = self.script.resolve(unresolvable=self.unresolvable).get_native(variable.variable_name)
return expected_type(out)
def try_get(self, variable: Variable, expected_type: Type[TType]) -> Optional[TType]:
def try_get(self, variable: Variable, expected_type: Type[TypeT]) -> Optional[TypeT]:
try:
return self.get(variable=variable, expected_type=expected_type)
except ScriptVariableNotResolved:

View file

@ -7,7 +7,7 @@ v: VariableDefinitions = VARIABLES
CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
"%extract_field_from_metadata_array_getter": "{ %map_get( %map(%array_at($0, 0)), %array_at($0, 1) ) }",
"%extract_field_from_metadata_array": f"""{{
"%extract_field_from_metadata_array": """{
%if(
%bool($0),
%array_extend(
@ -21,7 +21,7 @@ CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
),
[]
)
}}""",
}""",
"%extract_field_from_siblings": f"""{{
%if(
%bool({v.sibling_metadata.variable_name}),

View file

@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import Optional
# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion
# pylint: disable=no-member

View file

@ -1,12 +1,9 @@
import math
from typing import Union
from ytdl_sub.script.types.resolvable import AnyArgument
from ytdl_sub.script.types.resolvable import Boolean
from ytdl_sub.script.types.resolvable import Float
from ytdl_sub.script.types.resolvable import Integer
from ytdl_sub.script.types.resolvable import Numeric
from ytdl_sub.script.types.resolvable import String
def _to_numeric(value: int | float) -> Numeric:

View file

@ -71,7 +71,7 @@ class StringFunctions:
"""
Concatenate multiple Strings into a single String.
"""
return String("".join(list([val.value for val in values])))
return String("".join(val.value for val in values))
@staticmethod
def pad(string: String, length: Integer, char: String) -> String:

View file

@ -1,12 +1,7 @@
import copy
from collections import defaultdict
from typing import Dict
from typing import List
from typing import Optional
from typing import Set
from typing import Tuple
from mergedeep import mergedeep
from ytdl_sub.script.functions import Functions
from ytdl_sub.script.parser import parse
@ -17,12 +12,9 @@ from ytdl_sub.script.types.syntax_tree import SyntaxTree
from ytdl_sub.script.types.variable import Variable
from ytdl_sub.script.utils.exceptions import UNREACHABLE
from ytdl_sub.script.utils.exceptions import CycleDetected
from ytdl_sub.script.utils.exceptions import FunctionDoesNotExist
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
from ytdl_sub.script.utils.exceptions import InvalidCustomFunctionArguments
from ytdl_sub.script.utils.exceptions import RuntimeException
from ytdl_sub.script.utils.exceptions import ScriptBuilderMissingDefinitions
from ytdl_sub.script.utils.exceptions import VariableDoesNotExist
from ytdl_sub.script.utils.name_validation import validate_variable_name
from ytdl_sub.script.utils.type_checking import FunctionSpec

View file

@ -5,7 +5,6 @@ from typing import Dict
from typing import List
from typing import Type
from ytdl_sub.script.types.resolvable import AnyArgument
from ytdl_sub.script.types.resolvable import Argument
from ytdl_sub.script.types.resolvable import FutureResolvable
from ytdl_sub.script.types.resolvable import NonHashable

View file

@ -6,7 +6,6 @@ from typing import Dict
from typing import List
from typing import Type
from ytdl_sub.script.types.resolvable import AnyArgument
from ytdl_sub.script.types.resolvable import Argument
from ytdl_sub.script.types.resolvable import FutureResolvable
from ytdl_sub.script.types.resolvable import Hashable

View file

@ -21,7 +21,7 @@ from ytdl_sub.script.types.variable import FunctionArgument
from ytdl_sub.script.types.variable import Variable
from ytdl_sub.script.utils.exceptions import UNREACHABLE
TType = TypeVar("TType")
TypeT = TypeVar("TypeT")
@dataclass(frozen=True)
@ -31,8 +31,8 @@ class VariableDependency(ABC):
def _iterable_arguments(self) -> List[Argument]:
pass
def _recurse_get(self, ttype: Type[TType], subclass: bool = False) -> List[TType]:
output: List[TType] = []
def _recurse_get(self, ttype: Type[TypeT], subclass: bool = False) -> List[TypeT]:
output: List[TypeT] = []
for arg in self._iterable_arguments:
if subclass and issubclass(type(arg), ttype):
output.append(arg)

View file

@ -11,7 +11,6 @@ from typing import get_origin
from ytdl_sub.script.types.resolvable import Argument
from ytdl_sub.script.types.resolvable import BuiltInFunctionType
from ytdl_sub.script.types.resolvable import FunctionType
from ytdl_sub.script.types.resolvable import FutureResolvable
from ytdl_sub.script.types.resolvable import Lambda
from ytdl_sub.script.types.resolvable import LambdaReduce

View file

@ -3,9 +3,6 @@ from typing import Any
from typing import Dict
from typing import Iterable
from ytdl_sub.script.types.resolvable import Resolvable
from ytdl_sub.script.types.resolvable import String
class ScriptUtils:
@classmethod

View file

@ -2,10 +2,7 @@ import os
from pathlib import Path
from typing import Any
from ytdl_sub.script.parser import parse
from ytdl_sub.script.script import Script
from ytdl_sub.script.types.resolvable import String
from ytdl_sub.utils.scriptable import Scriptable
from ytdl_sub.validators.string_formatter_validators import OverridesStringFormatterValidator
from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator
from ytdl_sub.validators.validators import StringValidator

View file

@ -21,10 +21,9 @@ class StringDatetimeValidator(OverridesStringFormatterValidator):
_expected_value_type_name = "datetime string"
def apply_formatter(self, variable_dict: Dict[str, str]) -> str:
output = super().apply_formatter(variable_dict)
def post_process(self, resolved: str) -> str:
try:
_ = datetime_from_str(output)
_ = datetime_from_str(resolved)
except Exception as exc:
raise self._validation_exception(f"Invalid datetime string: {str(exc)}")
return output
return resolved

View file

@ -1,22 +1,15 @@
import re
from collections import OrderedDict
from keyword import iskeyword
from typing import Dict
from typing import List
from typing import Set
from typing import Union
from typing import final
from yt_dlp.utils import sanitize_filename
from ytdl_sub.entries.script.variable_definitions import VARIABLES
from ytdl_sub.script.parser import parse
from ytdl_sub.script.script import Script
from ytdl_sub.script.types.resolvable import Resolvable
from ytdl_sub.script.utils.exceptions import UserException
from ytdl_sub.script.utils.exceptions import VariableDoesNotExist
from ytdl_sub.utils.exceptions import InvalidVariableNameException
from ytdl_sub.utils.exceptions import StringFormattingException
from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException
from ytdl_sub.validators.validators import DictValidator
from ytdl_sub.validators.validators import ListValidator