Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Feb 19, 2024
1 parent 77cde57 commit 992d832
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 51 deletions.
6 changes: 3 additions & 3 deletions bolt/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions bolt/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions bolt/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion bolt/contrib/debug_codegen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Plugin for emitting generated code."""


__all__ = [
"DebugCodegenEmitter",
]
Expand Down
1 change: 0 additions & 1 deletion bolt/contrib/defer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Run deferred callbacks."""


__all__ = [
"Defer",
"DeferHandler",
Expand Down
1 change: 0 additions & 1 deletion bolt/contrib/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Plugin that sandboxes the bolt runtime."""


__all__ = [
"Sandbox",
"SandboxedAttributeHandler",
Expand Down
6 changes: 2 additions & 4 deletions bolt/loop_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions bolt/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def __call__(
*,
filename: Optional[str],
resource_location: Optional[str],
) -> AstRoot:
...
) -> AstRoot: ...


@dataclass
Expand All @@ -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

Expand Down
76 changes: 47 additions & 29 deletions bolt/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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] = []
Expand Down

0 comments on commit 992d832

Please sign in to comment.