Skip to content

Commit

Permalink
style: paint it black
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWii committed Aug 10, 2024
1 parent a5d39de commit b8a702b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 93 deletions.
9 changes: 7 additions & 2 deletions bolt_expressions/ast_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from mecha.utils import number_to_string
from nbtlib import Byte, Short, Int, Long, Float, Double # type: ignore

from .typing import NBT_TYPE_STRING, NbtTypeString, NumericNbtValue, unwrap_optional_type
from .typing import (
NBT_TYPE_STRING,
NbtTypeString,
NumericNbtValue,
unwrap_optional_type,
)
from .utils import insert_nested_commands, type_name

from .optimizer import (
Expand Down Expand Up @@ -412,7 +417,7 @@ def enable(self, node: IrUnary) -> Generator[IrNode, str, None]:

def serialize_nbt_type(self, value: Any) -> NbtTypeString:
value = unwrap_optional_type(value)

if isinstance(value, str) and value in NBT_TYPE_STRING:
return value

Expand Down
2 changes: 1 addition & 1 deletion bolt_expressions/contrib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def command(self, cmd_node: AstCommand):

if not value:
continue

arg_ast = self.mc.parse(
value, using=parser, provide={"properties": arg_node.properties}
)
Expand Down
24 changes: 14 additions & 10 deletions bolt_expressions/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from beet.core.utils import required_field

from .optimizer import CompositeNbtValue, IrCompositeLiteral, IrLiteral, IrOperation, IrSource
from .optimizer import (
CompositeNbtValue,
IrCompositeLiteral,
IrLiteral,
IrOperation,
IrSource,
)
from .typing import NbtValue, convert_tag
from .node import Expression, ExpressionNode, UnrollHelper
from .utils import type_name
Expand All @@ -29,29 +35,27 @@ def unroll(self, helper: UnrollHelper) -> tuple[Iterable[IrOperation], Any]:
def nested_unroll(obj: Any) -> CompositeNbtValue | IrSource:
if isinstance(obj, dict):
obj = cast(dict[str, Any], obj)
return {
key: nested_unroll(value)
for key, value in obj.items()
}
return {key: nested_unroll(value) for key, value in obj.items()}

if isinstance(obj, list):
obj = cast(list[Any], obj)
return [nested_unroll(value) for value in obj]

if isinstance(obj, ExpressionNode):
ops, value = obj.unroll(helper)
operations.extend(ops)

return value.value if isinstance(value, IrLiteral) else value

value = convert_tag(obj)

if value is None:
raise ValueError(f'Invalid literal of type {type_name(obj)} "{self.value}"')
raise ValueError(
f'Invalid literal of type {type_name(obj)} "{self.value}"'
)

return value


if self.nbt is None:
value = nested_unroll(self.value)

Expand Down
5 changes: 0 additions & 5 deletions bolt_expressions/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,9 @@ def __init__(self, ctx: Context):
convert_data_order_operation, opt=self.optimizer
),
discard_casting=discard_casting,

# features
data_set_scaling=partial(data_set_scaling, opt=self.optimizer),
data_get_scaling=data_get_scaling,

# cleanup
multiply_divide_by_fraction=multiply_divide_by_fraction,
multiply_divide_by_one_removal=multiply_divide_by_one_removal,
Expand All @@ -277,19 +275,16 @@ def __init__(self, ctx: Context):
convert_defined_boolean_condition=partial(
convert_defined_boolean_condition, opt=self.optimizer
),

# typing
type_caster=self.type_caster,
type_checker=self.type_checker,

# post type-checking cleanup
discard_non_numerical_casting=discard_non_numerical_casting,
source_copy_elision_post=partial(source_copy_elision, opt=self.optimizer),
set_to_self_removal=set_to_self_removal,
set_and_get_cleanup=set_and_get_cleanup,
store_result_inlining=store_result_inlining,
deadcode_elimination=partial(deadcode_elimination, opt=self.optimizer),

init_score_boolean_result=init_score_boolean_result,
rename_temp_scores=partial(rename_temp_scores, self.optimizer),
)
Expand Down
Loading

0 comments on commit b8a702b

Please sign in to comment.