Format using black

This commit is contained in:
James Westman 2022-12-19 11:49:10 -06:00
parent 6a36d92380
commit 8fee46ec68
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
40 changed files with 975 additions and 610 deletions

View file

@ -26,19 +26,23 @@ from .common import *
class Signal(AstNode):
grammar = Statement(
UseIdent("name"),
Optional([
"::",
UseIdent("detail_name").expected("a signal detail name"),
]),
Optional(
[
"::",
UseIdent("detail_name").expected("a signal detail name"),
]
),
"=>",
UseIdent("handler").expected("the name of a function to handle the signal"),
Match("(").expected("argument list"),
Optional(UseIdent("object")).expected("object identifier"),
Match(")").expected(),
ZeroOrMore(AnyOf(
[Keyword("swapped"), UseLiteral("swapped", True)],
[Keyword("after"), UseLiteral("after", True)],
)),
ZeroOrMore(
AnyOf(
[Keyword("swapped"), UseLiteral("swapped", True)],
[Keyword("after"), UseLiteral("after", True)],
)
),
)
@property
@ -65,18 +69,15 @@ class Signal(AstNode):
def is_after(self) -> bool:
return self.tokens["after"] or False
@property
def gir_signal(self):
if self.gir_class is not None:
return self.gir_class.signals.get(self.tokens["name"])
@property
def gir_class(self):
return self.parent.parent.gir_class
@validate("name")
def signal_exists(self):
if self.gir_class is None:
@ -92,10 +93,9 @@ class Signal(AstNode):
if self.gir_signal is None:
raise CompileError(
f"Class {self.gir_class.full_name} does not contain a signal called {self.tokens['name']}",
did_you_mean=(self.tokens["name"], self.gir_class.signals.keys())
did_you_mean=(self.tokens["name"], self.gir_class.signals.keys()),
)
@validate("object")
def object_exists(self):
object_id = self.tokens["object"]
@ -103,10 +103,7 @@ class Signal(AstNode):
return
if self.root.objects_by_id.get(object_id) is None:
raise CompileError(
f"Could not find object with ID '{object_id}'"
)
raise CompileError(f"Could not find object with ID '{object_id}'")
@docs("name")
def signal_docs(self):