more linting
This commit is contained in:
parent
acceb50377
commit
7775022ef4
9 changed files with 15 additions and 77 deletions
|
|
@ -1,4 +1,3 @@
|
|||
from contextlib import contextmanager
|
||||
from enum import Enum
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
|
@ -16,9 +15,9 @@ from ytdl_sub.script.types.resolvable import String
|
|||
from ytdl_sub.script.types.syntax_tree import SyntaxTree
|
||||
from ytdl_sub.script.types.variable import FunctionArgument
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
from ytdl_sub.script.utils.exceptions import UnreachableSyntaxException
|
||||
from ytdl_sub.script.utils.exceptions import UserException
|
||||
from ytdl_sub.script.utils.parser_exception_formatter import ParserExceptionFormatter
|
||||
from ytdl_sub.utils.exceptions import StringFormattingException
|
||||
|
|
@ -35,12 +34,6 @@ class ArgumentParser(Enum):
|
|||
MAP_VALUE = "map value"
|
||||
|
||||
|
||||
UNREACHABLE = UnreachableSyntaxException(
|
||||
"If you see this error, you have discovered a bug in the script parser!\n"
|
||||
"Please upload your config/subscription file(s) to and make a GitHub issue at "
|
||||
"https://github.com/jmbannon/ytdl-sub/issues"
|
||||
)
|
||||
|
||||
BRACKET_NOT_CLOSED = InvalidSyntaxException("Bracket not properly closed")
|
||||
|
||||
NUMERICS_ONLY_ARGS = InvalidSyntaxException(
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from ytdl_sub.script.types.resolvable import Resolvable
|
|||
from ytdl_sub.script.types.variable import FunctionArgument
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.types.variable_dependency import VariableDependency
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||
from ytdl_sub.utils.exceptions import StringFormattingException
|
||||
|
||||
|
|
@ -113,10 +114,10 @@ class FunctionInputSpec:
|
|||
def is_compatible(self, input_args: List[ArgumentType]) -> bool:
|
||||
if self.args is not None:
|
||||
return self._is_args_compatible(input_args=input_args)
|
||||
elif self.varargs is not None:
|
||||
if self.varargs is not None:
|
||||
return self._is_varargs_compatible(input_args=input_args)
|
||||
else:
|
||||
assert False, "should never reach here"
|
||||
|
||||
raise UNREACHABLE # TODO: functions with no args
|
||||
|
||||
def expected_args_str(self) -> str:
|
||||
def to_human_readable_name(python_type: Type[NamedType] | Type[Union[NamedType]]) -> str:
|
||||
|
|
@ -128,8 +129,9 @@ class FunctionInputSpec:
|
|||
|
||||
if self.args is not None:
|
||||
return f"({', '.join([to_human_readable_name(type_) for type_ in self.args])})"
|
||||
elif self.varargs is not None:
|
||||
if self.varargs is not None:
|
||||
return f"({to_human_readable_name(self.varargs.__name__)}, ...)"
|
||||
return "()"
|
||||
|
||||
@classmethod
|
||||
def from_function(cls, func: "BuiltInFunction") -> "FunctionInputSpec":
|
||||
|
|
@ -233,7 +235,7 @@ class BuiltInFunction(Function):
|
|||
else:
|
||||
received_type_names.append(arg.type_name())
|
||||
|
||||
received_args_str = f"({', '.join([name for name in received_type_names])})"
|
||||
received_args_str = f"({', '.join(name for name in received_type_names)})"
|
||||
|
||||
return f"Expected {self.input_spec.expected_args_str()}\nReceived {received_args_str}"
|
||||
|
||||
|
|
|
|||
|
|
@ -17,3 +17,10 @@ class IncompatibleFunctionArguments(UserException):
|
|||
|
||||
class UnreachableSyntaxException(InvalidSyntaxException):
|
||||
"""For use in places where code _should_ never reach, but might from bugs"""
|
||||
|
||||
|
||||
UNREACHABLE = UnreachableSyntaxException(
|
||||
"If you see this error, you have discovered a bug in the script parser!\n"
|
||||
"Please upload your config/subscription file(s) to and make a GitHub issue at "
|
||||
"https://github.com/jmbannon/ytdl-sub/issues"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -34,29 +34,6 @@ class TestParser:
|
|||
]
|
||||
)
|
||||
|
||||
# def test_array(self):
|
||||
# parsed = parse("hello {['elem1', 'elem2']}")
|
||||
# parsed_empty = parse("hello {[]}")
|
||||
# parsed_with_var = parse("hello {['elem1', variable_name]}")
|
||||
# parsed_extend = parse(
|
||||
# "hi {%at(%flatten_array(%extend(['elem1', 'elem2'], ['elem3'], [['elem4'], ['elem5', 'elem6']], ['elem7'])), 1)}"
|
||||
# )
|
||||
# parsed_extend.resolve({})
|
||||
# assert False
|
||||
#
|
||||
# def test_map(self):
|
||||
# parsed = parse("hello {%map(['elem1', 'elem2'])}")
|
||||
# parsed_empty = parse("hello {%map()}")
|
||||
# parsed_with_var = parse("hello {%map([variable_name, 'elem2'])}")
|
||||
# parsed_extend = parse("hi {%map([variable_name, 'elem2'], ['elem3', variable_name])}")
|
||||
# parse_raw_map = parse("hello {{'key': 'value'}}")
|
||||
# parsed_extend.resolve({})
|
||||
# assert False
|
||||
#
|
||||
# def test_function_argument(self):
|
||||
# parsed = parse("hello {%map([$1, $2])}")
|
||||
# assert False
|
||||
|
||||
def test_conditional(self):
|
||||
parsed = parse("hello {%if(True, 'hi', 3.4)}")
|
||||
assert parsed == SyntaxTree(
|
||||
|
|
|
|||
|
|
@ -1,19 +1,10 @@
|
|||
import re
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import BOOLEAN_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import NUMERICS_INVALID_CHAR
|
||||
from ytdl_sub.script.parser import NUMERICS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import UNEXPECTED_CHAR_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.parser import ArgumentParser
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
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 String
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,12 @@
|
|||
import re
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import NUMERICS_INVALID_CHAR
|
||||
from ytdl_sub.script.parser import NUMERICS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import UNEXPECTED_CHAR_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.parser import ArgumentParser
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
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 String
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,11 @@
|
|||
import re
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import NUMERICS_INVALID_CHAR
|
||||
from ytdl_sub.script.parser import NUMERICS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import STRINGS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import UNEXPECTED_CHAR_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.parser import ArgumentParser
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
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 String
|
||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
||||
|
||||
def _incompatible_arguments_match(expected: str, recieved: str) -> str:
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
import re
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import NUMERICS_INVALID_CHAR
|
||||
from ytdl_sub.script.parser import NUMERICS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import UNEXPECTED_CHAR_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.parser import ArgumentParser
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
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 String
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
|
|
|||
|
|
@ -1,20 +1,11 @@
|
|||
import re
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import NUMERICS_INVALID_CHAR
|
||||
from ytdl_sub.script.parser import NUMERICS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import STRINGS_NOT_CLOSED
|
||||
from ytdl_sub.script.parser import STRINGS_ONLY_ARGS
|
||||
from ytdl_sub.script.parser import UNEXPECTED_CHAR_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.parser import ArgumentParser
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
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 String
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue