cleanup: Format using black

This commit is contained in:
James Westman 2022-02-23 14:09:18 -06:00
parent 4b42016837
commit af03c2ac0f
36 changed files with 928 additions and 616 deletions

View file

@ -46,7 +46,7 @@ class TranslatedStringValue(Value):
@property
def attrs(self):
attrs = { "translatable": "true" }
attrs = {"translatable": "true"}
if "context" in self.tokens:
attrs["context"] = self.tokens["context"]
return attrs
@ -71,7 +71,9 @@ class LiteralValue(Value):
try:
int(self.tokens["value"])
except:
raise CompileError(f"Cannot convert {self.group.tokens['value']} to integer")
raise CompileError(
f"Cannot convert {self.group.tokens['value']} to integer"
)
elif isinstance(type, gir.UIntType):
try:
@ -79,13 +81,17 @@ class LiteralValue(Value):
if int(self.tokens["value"]) < 0:
raise Exception()
except:
raise CompileError(f"Cannot convert {self.group.tokens['value']} to unsigned integer")
raise CompileError(
f"Cannot convert {self.group.tokens['value']} to unsigned integer"
)
elif isinstance(type, gir.FloatType):
try:
float(self.tokens["value"])
except:
raise CompileError(f"Cannot convert {self.group.tokens['value']} to float")
raise CompileError(
f"Cannot convert {self.group.tokens['value']} to float"
)
elif isinstance(type, gir.StringType):
pass
@ -100,15 +106,20 @@ class LiteralValue(Value):
"Gtk.ShortcutAction",
]
if type.full_name not in parseable_types:
raise CompileError(f"Cannot convert {self.group.tokens['value']} to {type.full_name}")
raise CompileError(
f"Cannot convert {self.group.tokens['value']} to {type.full_name}"
)
elif type is not None:
raise CompileError(f"Cannot convert {self.group.tokens['value']} to {type.full_name}")
raise CompileError(
f"Cannot convert {self.group.tokens['value']} to {type.full_name}"
)
class Flag(AstNode):
grammar = UseIdent("value")
class FlagsValue(Value):
grammar = [Flag, "|", Delimited(Flag, "|")]
@ -133,14 +144,14 @@ class IdentValue(Value):
if self.tokens["value"] not in type.members:
raise CompileError(
f"{self.tokens['value']} is not a member of {type.full_name}",
did_you_mean=(self.tokens['value'], type.members.keys()),
did_you_mean=(self.tokens["value"], type.members.keys()),
)
elif isinstance(type, gir.BoolType):
if self.tokens["value"] not in ["true", "false"]:
raise CompileError(
f"Expected 'true' or 'false' for boolean value",
did_you_mean=(self.tokens['value'], ["true", "false"]),
did_you_mean=(self.tokens["value"], ["true", "false"]),
)
elif type is not None:
@ -148,14 +159,13 @@ class IdentValue(Value):
if object is None:
raise CompileError(
f"Could not find object with ID {self.tokens['value']}",
did_you_mean=(self.tokens['value'], self.root.objects_by_id.keys()),
did_you_mean=(self.tokens["value"], self.root.objects_by_id.keys()),
)
elif object.gir_class and not object.gir_class.assignable_to(type):
raise CompileError(
f"Cannot assign {object.gir_class.full_name} to {type.full_name}"
)
@docs()
def docs(self):
type = self.parent.value_type
@ -167,9 +177,7 @@ class IdentValue(Value):
elif isinstance(type, gir.GirNode):
return type.doc
def get_semantic_tokens(self) -> T.Iterator[SemanticToken]:
if isinstance(self.parent.value_type, gir.Enumeration):
token = self.group.tokens["value"]
yield SemanticToken(token.start, token.end, SemanticTokenType.EnumMember)