From 992d832f80e1d8a44beab6e29f4398e9648331e0 Mon Sep 17 00:00:00 2001 From: Valentin Berlier Date: Tue, 20 Feb 2024 00:30:20 +0100 Subject: [PATCH] chore: reformat --- bolt/ast.py | 6 +-- bolt/codegen.py | 6 +-- bolt/commands.py | 4 +- bolt/contrib/debug_codegen.py | 1 - bolt/contrib/defer.py | 1 - bolt/contrib/sandbox.py | 1 - bolt/loop_info.py | 6 +-- bolt/module.py | 9 ++--- bolt/parse.py | 76 ++++++++++++++++++++++------------- 9 files changed, 59 insertions(+), 51 deletions(-) diff --git a/bolt/ast.py b/bolt/ast.py index d8543a4..f52102e 100644 --- a/bolt/ast.py +++ b/bolt/ast.py @@ -229,9 +229,9 @@ class AstCall(AstExpression): """Ast call node.""" value: AstExpression = required_field() - arguments: AstChildren[ - Union[AstExpression, AstUnpack, AstKeyword] - ] = required_field() + arguments: AstChildren[Union[AstExpression, AstUnpack, AstKeyword]] = ( + required_field() + ) @dataclass(frozen=True, slots=True) diff --git a/bolt/codegen.py b/bolt/codegen.py index 21b5277..ab0d87c 100644 --- a/bolt/codegen.py +++ b/bolt/codegen.py @@ -364,16 +364,14 @@ def flush(self) -> str: @overload def visit_single( node: AstNode, -) -> Generator[AstNode, Optional[List[str]], Optional[str]]: - ... +) -> Generator[AstNode, Optional[List[str]], Optional[str]]: ... @overload def visit_single( node: AstNode, required: Literal[True], -) -> Generator[AstNode, Optional[List[str]], str]: - ... +) -> Generator[AstNode, Optional[List[str]], str]: ... def visit_single( diff --git a/bolt/commands.py b/bolt/commands.py index b8a2bac..d2a3020 100644 --- a/bolt/commands.py +++ b/bolt/commands.py @@ -94,9 +94,7 @@ def memo( with message_fence( "Clearing memo..." if clear - else "Running garbage collection..." - if gc - else "Inspecting memo..." + else "Running garbage collection..." if gc else "Inspecting memo..." ): if not keys: click.echo("The memo registry is empty.\n") diff --git a/bolt/contrib/debug_codegen.py b/bolt/contrib/debug_codegen.py index f2dabdf..0ba5b12 100644 --- a/bolt/contrib/debug_codegen.py +++ b/bolt/contrib/debug_codegen.py @@ -1,6 +1,5 @@ """Plugin for emitting generated code.""" - __all__ = [ "DebugCodegenEmitter", ] diff --git a/bolt/contrib/defer.py b/bolt/contrib/defer.py index c90ba41..8003bef 100644 --- a/bolt/contrib/defer.py +++ b/bolt/contrib/defer.py @@ -1,6 +1,5 @@ """Run deferred callbacks.""" - __all__ = [ "Defer", "DeferHandler", diff --git a/bolt/contrib/sandbox.py b/bolt/contrib/sandbox.py index 21d7c18..b2cd857 100644 --- a/bolt/contrib/sandbox.py +++ b/bolt/contrib/sandbox.py @@ -1,6 +1,5 @@ """Plugin that sandboxes the bolt runtime.""" - __all__ = [ "Sandbox", "SandboxedAttributeHandler", diff --git a/bolt/loop_info.py b/bolt/loop_info.py index d5923f7..efd6fda 100644 --- a/bolt/loop_info.py +++ b/bolt/loop_info.py @@ -46,12 +46,10 @@ def __next__(self) -> Tuple["LoopInfo[T]", T]: return self, self.current @overload - def peek(self, offset: int) -> Optional[T]: - ... + def peek(self, offset: int) -> Optional[T]: ... @overload - def peek(self, offset: int, default: U) -> Union[T, U]: - ... + def peek(self, offset: int, default: U) -> Union[T, U]: ... def peek(self, offset: int, default: Any = None) -> Any: index = self.index + offset diff --git a/bolt/module.py b/bolt/module.py index 3aabad8..733eff0 100644 --- a/bolt/module.py +++ b/bolt/module.py @@ -137,8 +137,7 @@ def __call__( *, filename: Optional[str], resource_location: Optional[str], - ) -> AstRoot: - ... + ) -> AstRoot: ... @dataclass @@ -161,9 +160,9 @@ class ModuleManager(Mapping[TextFileBase[Any], CompiledModule]): ) globals: JsonDict = extra_field(default_factory=dict) builtins: Set[str] = extra_field(default_factory=set) - prelude: Dict[ - str, Dict[Optional[Union[ResourcePack, DataPack]], AstPrelude] - ] = extra_field(default_factory=dict) + prelude: Dict[str, Dict[Optional[Union[ResourcePack, DataPack]], AstPrelude]] = ( + extra_field(default_factory=dict) + ) execution_count: int = 0 diff --git a/bolt/parse.py b/bolt/parse.py index f64c912..25ab099 100644 --- a/bolt/parse.py +++ b/bolt/parse.py @@ -621,9 +621,12 @@ def __call__(self, stream: TokenStream) -> Any: elif isinstance(item, AstImportedItem): lexical_scope.bind_variable(item.name, item) - with self.modules.parse_push(current), stream.provide( - resource_location=resource_location, - lexical_scope=lexical_scope, + with ( + self.modules.parse_push(current), + stream.provide( + resource_location=resource_location, + lexical_scope=lexical_scope, + ), ): node = self.parser(stream) @@ -996,9 +999,13 @@ def resolve(self, node: AstRoot) -> AstRoot: if len(binding.references) > refcount ) node = set_location( - AstEscapeRoot(commands=AstChildren(commands), identifiers=identifiers) - if identifiers - else AstRoot(commands=AstChildren(commands)), + ( + AstEscapeRoot( + commands=AstChildren(commands), identifiers=identifiers + ) + if identifiers + else AstRoot(commands=AstChildren(commands)) + ), node, ) elif should_replace: @@ -2377,10 +2384,13 @@ def __call__(self, stream: TokenStream) -> Any: stop = None step = None - with stream.provide(bolt_lookup=True), stream.syntax( - colon=r":", - comma=r",", - bracket=r"\]", + with ( + stream.provide(bolt_lookup=True), + stream.syntax( + colon=r":", + comma=r",", + bracket=r"\]", + ), ): colon1 = stream.get("colon") @@ -2455,12 +2465,15 @@ def __call__(self, stream: TokenStream) -> Any: elif token and token.match("format_string"): quote = token.value[-1] - with stream.provide(bolt_format_string=True), stream.syntax( - escape=rf"\\.", - double_brace=r"\{\{|\}\}", - brace=r"\{|\}", - quote=quote, - text=r"[^\\]+?", + with ( + stream.provide(bolt_format_string=True), + stream.syntax( + escape=rf"\\.", + double_brace=r"\{\{|\}\}", + brace=r"\{|\}", + quote=quote, + text=r"[^\\]+?", + ), ): fmt = quote values: List[AstExpression] = [] @@ -2506,11 +2519,13 @@ def __call__(self, stream: TokenStream) -> Any: return node elif token and token.match("nested_location"): - with stream.intercept("whitespace"), stream.provide( - bolt_nested_location=True - ), stream.syntax( - path=r"[0-9a-z_./-]+", - curly=r"\{|\}", + with ( + stream.intercept("whitespace"), + stream.provide(bolt_nested_location=True), + stream.syntax( + path=r"[0-9a-z_./-]+", + curly=r"\{|\}", + ), ): fmt = "" values: List[AstExpression] = [] @@ -2540,14 +2555,17 @@ def __call__(self, stream: TokenStream) -> Any: else: node = self.parser(stream) - with stream.intercept(*["whitespace"] * self.truncate), stream.syntax( - dot=r"\.", - comma=r",", - brace=r"\(|\)", - bracket=r"\[|\]", - identifier=IDENTIFIER_PATTERN, - string=STRING_PATTERN, - number=r"(?:0|[1-9][0-9]*)", + with ( + stream.intercept(*["whitespace"] * self.truncate), + stream.syntax( + dot=r"\.", + comma=r",", + brace=r"\(|\)", + bracket=r"\[|\]", + identifier=IDENTIFIER_PATTERN, + string=STRING_PATTERN, + number=r"(?:0|[1-9][0-9]*)", + ), ): while token := stream.get("dot", ("brace", "("), ("bracket", "[")): arguments: List[Any] = []