This commit is contained in:
Jesse Bannon 2023-09-20 13:45:21 -07:00
parent 9a62aebb8d
commit 6c1ce8b820
6 changed files with 67 additions and 57 deletions

View file

@ -0,0 +1,5 @@
from ytdl_sub.script.functions.string_functions import StringFunctions
class Functions(StringFunctions):
pass

View file

@ -1,43 +1,4 @@
from abc import ABC
from dataclasses import dataclass
from typing import Generic
from typing import TypeVar
T = TypeVar("T")
NumericT = TypeVar("NumericT", bound=int | float)
@dataclass(frozen=True)
class Resolvable(ABC, Generic[T]):
value: T
def resolve(self) -> str:
return str(self.value)
@dataclass(frozen=True)
class Numeric(Resolvable[NumericT], ABC, Generic[NumericT]):
pass
@dataclass(frozen=True)
class Integer(Resolvable[int]):
pass
@dataclass(frozen=True)
class Float(Resolvable[float]):
pass
@dataclass(frozen=True)
class Boolean(Resolvable[bool]):
pass
@dataclass(frozen=True)
class String(Resolvable[str]):
pass
from ytdl_sub.script.types import String
class StringFunctions:
@ -71,7 +32,3 @@ class StringFunctions:
@staticmethod
def concat(l_string: String, r_string: String) -> String:
return String(f"{l_string}{r_string}")
class Functions(StringFunctions):
pass

View file

@ -1,14 +1,14 @@
from typing import List
from typing import Optional
from ytdl_sub.script.functions import Boolean
from ytdl_sub.script.functions import Float
from ytdl_sub.script.functions import Integer
from ytdl_sub.script.functions import String
from ytdl_sub.script.syntax_tree import ArgumentType
from ytdl_sub.script.syntax_tree import Function
from ytdl_sub.script.syntax_tree import SyntaxTree
from ytdl_sub.script.syntax_tree import Variable
from ytdl_sub.script.types import Boolean
from ytdl_sub.script.types import Float
from ytdl_sub.script.types import Integer
from ytdl_sub.script.types import String
from ytdl_sub.utils.exceptions import StringFormattingException
from ytdl_sub.validators.string_formatter_validators import is_valid_source_variable_name

View file

@ -8,12 +8,12 @@ from typing import Set
from typing import Union
from typing import final
from ytdl_sub.script.functions import Boolean
from ytdl_sub.script.functions import Float
from ytdl_sub.script.functions import Functions
from ytdl_sub.script.functions import Integer
from ytdl_sub.script.functions import Resolvable
from ytdl_sub.script.functions import String
from ytdl_sub.script.types import Boolean
from ytdl_sub.script.types import Float
from ytdl_sub.script.types import Integer
from ytdl_sub.script.types import Resolvable
from ytdl_sub.script.types import String
from ytdl_sub.utils.exceptions import StringFormattingException

View file

@ -0,0 +1,48 @@
from abc import ABC
from abc import abstractmethod
from dataclasses import dataclass
from typing import Generic
from typing import TypeVar
T = TypeVar("T")
NumericT = TypeVar("NumericT", bound=int | float)
@dataclass(frozen=True)
class Resolvable(ABC):
@abstractmethod
def resolve(self) -> str:
...
@dataclass(frozen=True)
class ResolvableT(Resolvable, Generic[T]):
value: T
def resolve(self) -> str:
return str(self.value)
@dataclass(frozen=True)
class Numeric(ResolvableT[NumericT], ABC, Generic[NumericT]):
pass
@dataclass(frozen=True)
class Integer(ResolvableT[int]):
pass
@dataclass(frozen=True)
class Float(ResolvableT[float]):
pass
@dataclass(frozen=True)
class Boolean(ResolvableT[bool]):
pass
@dataclass(frozen=True)
class String(ResolvableT[str]):
pass

View file

@ -1,13 +1,13 @@
import pytest
from ytdl_sub.script.functions import Boolean
from ytdl_sub.script.functions import Float
from ytdl_sub.script.functions import Integer
from ytdl_sub.script.functions import String
from ytdl_sub.script.parser import parse
from ytdl_sub.script.syntax_tree import Function
from ytdl_sub.script.syntax_tree import SyntaxTree
from ytdl_sub.script.syntax_tree import Variable
from ytdl_sub.script.types import Boolean
from ytdl_sub.script.types import Float
from ytdl_sub.script.types import Integer
from ytdl_sub.script.types import String
from ytdl_sub.utils.exceptions import StringFormattingException