organize
This commit is contained in:
parent
9a62aebb8d
commit
6c1ce8b820
6 changed files with 67 additions and 57 deletions
5
src/ytdl_sub/script/functions/__init__.py
Normal file
5
src/ytdl_sub/script/functions/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from ytdl_sub.script.functions.string_functions import StringFunctions
|
||||
|
||||
|
||||
class Functions(StringFunctions):
|
||||
pass
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
48
src/ytdl_sub/script/types.py
Normal file
48
src/ytdl_sub/script/types.py
Normal 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
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue