From ab9d902cc5e63ee503a627c8406240c86a4556f9 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Tue, 24 Dec 2024 10:41:35 -0500 Subject: [PATCH] fix formatting and some tests --- blueprintcompiler/language/gtk_menu.py | 2 +- blueprintcompiler/language/values.py | 4 ++-- blueprintcompiler/language/variant.py | 2 +- blueprintcompiler/utils.py | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/blueprintcompiler/language/gtk_menu.py b/blueprintcompiler/language/gtk_menu.py index a703a76..5a6627a 100644 --- a/blueprintcompiler/language/gtk_menu.py +++ b/blueprintcompiler/language/gtk_menu.py @@ -98,7 +98,7 @@ class MenuAttribute(AstNode): return self.tokens["name"] @property - def value(self) -> StringValue | VariantValue: + def value(self) -> T.Union[StringValue, VariantValue]: if len(self.children[StringValue]) > 0: return self.children[StringValue][0] elif len(self.children[VariantValue]) > 0: diff --git a/blueprintcompiler/language/values.py b/blueprintcompiler/language/values.py index 4d355c9..021cf90 100644 --- a/blueprintcompiler/language/values.py +++ b/blueprintcompiler/language/values.py @@ -29,6 +29,7 @@ from .types import TypeName from .variant import VarContent import gi + gi.require_version("GLib", "2.0") from gi.repository import GLib @@ -377,7 +378,6 @@ class IdentLiteral(AstNode): return None - class VariantValue(AstNode): grammar = [ "variant", @@ -424,7 +424,7 @@ class VariantValue(AstNode): def validate_type(self): if not GLib.VariantType.string_is_valid(self.var_type): raise CompileError(f"`{self.var_type}` is not a valid variant type") - + @validate() def validate_content(self): if not GLib.VariantType.string_is_valid(self.var_type): diff --git a/blueprintcompiler/language/variant.py b/blueprintcompiler/language/variant.py index bc0988f..450a0c8 100644 --- a/blueprintcompiler/language/variant.py +++ b/blueprintcompiler/language/variant.py @@ -8,7 +8,7 @@ from .contexts import ScopeCtx, ValueTypeCtx from .gobject_object import Object from .types import TypeName -VAR_CONTENT_HOOKS = [] +VAR_CONTENT_HOOKS: list[T.Any] = [] class VarContent(AstNode): diff --git a/blueprintcompiler/utils.py b/blueprintcompiler/utils.py index f579ea4..b05c9cd 100644 --- a/blueprintcompiler/utils.py +++ b/blueprintcompiler/utils.py @@ -156,6 +156,7 @@ def unescape_quote(string: str) -> str: return result + def iter_batched(iterable, n, *, strict=False): """ Replacement for `itertools.batched()` since the testing infrastructure @@ -163,9 +164,9 @@ def iter_batched(iterable, n, *, strict=False): """ # batched('ABCDEFG', 3) → ABC DEF G if n < 1: - raise ValueError('n must be at least one') + raise ValueError("n must be at least one") iterator = iter(iterable) while batch := tuple(itertools.islice(iterator, n)): if strict and len(batch) != n: - raise ValueError('batched(): incomplete batch') - yield batch \ No newline at end of file + raise ValueError("batched(): incomplete batch") + yield batch