mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
fix formatting and some tests
This commit is contained in:
parent
c708532a8d
commit
ab9d902cc5
4 changed files with 8 additions and 7 deletions
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
raise ValueError("batched(): incomplete batch")
|
||||
yield batch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue