From a9f6bf8d89400b2fa0d5dc7a4e734d0ea278cce1 Mon Sep 17 00:00:00 2001 From: James Westman Date: Tue, 11 Apr 2023 21:26:37 -0500 Subject: [PATCH] Remove unused imports and code --- blueprintcompiler/completions.py | 2 +- blueprintcompiler/language/__init__.py | 2 +- blueprintcompiler/language/attributes.py | 6 ------ blueprintcompiler/language/binding.py | 1 - blueprintcompiler/language/gobject_property.py | 3 --- blueprintcompiler/language/gtk_a11y.py | 7 ++++--- blueprintcompiler/language/gtk_combo_box_text.py | 1 - blueprintcompiler/language/gtk_layout.py | 1 - blueprintcompiler/language/gtk_menu.py | 11 ----------- blueprintcompiler/language/gtk_string_list.py | 1 - blueprintcompiler/language/gtk_styles.py | 4 ++++ blueprintcompiler/language/property_binding.py | 1 - blueprintcompiler/language/types.py | 1 - blueprintcompiler/language/values.py | 2 -- blueprintcompiler/outputs/xml/__init__.py | 4 ++-- 15 files changed, 12 insertions(+), 35 deletions(-) diff --git a/blueprintcompiler/completions.py b/blueprintcompiler/completions.py index 6a944dd..fc6eeee 100644 --- a/blueprintcompiler/completions.py +++ b/blueprintcompiler/completions.py @@ -126,7 +126,7 @@ def property_completer(ast_node, match_variables): @completer( - applies_in=[language.Property, language.BaseTypedAttribute], + applies_in=[language.Property, language.BaseAttribute], matches=[[(TokenType.IDENT, None), (TokenType.OP, ":")]], ) def prop_value_completer(ast_node, match_variables): diff --git a/blueprintcompiler/language/__init__.py b/blueprintcompiler/language/__init__.py index f544204..b5e2f04 100644 --- a/blueprintcompiler/language/__init__.py +++ b/blueprintcompiler/language/__init__.py @@ -1,6 +1,6 @@ from .gtk_list_item_factory import ExtListItemFactory from .adw_message_dialog import ExtAdwMessageDialog -from .attributes import BaseAttribute, BaseTypedAttribute +from .attributes import BaseAttribute from .binding import Binding from .contexts import ValueTypeCtx from .expression import ( diff --git a/blueprintcompiler/language/attributes.py b/blueprintcompiler/language/attributes.py index c713917..8ff1f0b 100644 --- a/blueprintcompiler/language/attributes.py +++ b/blueprintcompiler/language/attributes.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .values import Value, Translated from .common import * @@ -31,8 +30,3 @@ class BaseAttribute(AstNode): @property def name(self): return self.tokens["name"] - - -class BaseTypedAttribute(BaseAttribute): - """A BaseAttribute whose parent has a value_type property that can assist - in validation.""" diff --git a/blueprintcompiler/language/binding.py b/blueprintcompiler/language/binding.py index 88105fc..b13d5da 100644 --- a/blueprintcompiler/language/binding.py +++ b/blueprintcompiler/language/binding.py @@ -21,7 +21,6 @@ from dataclasses import dataclass from .common import * from .expression import Expression, LookupOp, LiteralExpr -from .contexts import ValueTypeCtx class Binding(AstNode): diff --git a/blueprintcompiler/language/gobject_property.py b/blueprintcompiler/language/gobject_property.py index b52feb9..31ff40d 100644 --- a/blueprintcompiler/language/gobject_property.py +++ b/blueprintcompiler/language/gobject_property.py @@ -17,10 +17,7 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from dataclasses import dataclass -from .expression import Expression -from .gobject_object import Object from .gtkbuilder_template import Template from .values import Value, ObjectValue from .common import * diff --git a/blueprintcompiler/language/gtk_a11y.py b/blueprintcompiler/language/gtk_a11y.py index 930606c..c378927 100644 --- a/blueprintcompiler/language/gtk_a11y.py +++ b/blueprintcompiler/language/gtk_a11y.py @@ -18,10 +18,11 @@ # SPDX-License-Identifier: LGPL-3.0-or-later from .gobject_object import ObjectContent, validate_parent_type -from .attributes import BaseTypedAttribute +from .attributes import BaseAttribute from .values import Value from .common import * from .contexts import ValueTypeCtx +from ..decompiler import escape_quote def get_property_types(gir): @@ -105,7 +106,7 @@ def _get_docs(gir, name): return gir_type.doc -class A11yProperty(BaseTypedAttribute): +class A11yProperty(BaseAttribute): grammar = Statement( UseIdent("name"), ":", @@ -208,7 +209,7 @@ def decompile_relation(ctx, gir, name, cdata): @decompiler("state", cdata=True) def decompile_state(ctx, gir, name, cdata, translatable="false"): if decompile.truthy(translatable): - ctx.print(f'{name}: _("{_escape_quote(cdata)}");') + ctx.print(f'{name}: _("{escape_quote(cdata)}");') else: ctx.print_attribute(name, cdata, get_types(ctx.gir).get(name)) diff --git a/blueprintcompiler/language/gtk_combo_box_text.py b/blueprintcompiler/language/gtk_combo_box_text.py index 527ff50..d55481d 100644 --- a/blueprintcompiler/language/gtk_combo_box_text.py +++ b/blueprintcompiler/language/gtk_combo_box_text.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .attributes import BaseTypedAttribute from .gobject_object import ObjectContent, validate_parent_type from .common import * from .contexts import ValueTypeCtx diff --git a/blueprintcompiler/language/gtk_layout.py b/blueprintcompiler/language/gtk_layout.py index 83a5fcc..7616e57 100644 --- a/blueprintcompiler/language/gtk_layout.py +++ b/blueprintcompiler/language/gtk_layout.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .attributes import BaseAttribute from .gobject_object import ObjectContent, validate_parent_type from .common import * from .contexts import ValueTypeCtx diff --git a/blueprintcompiler/language/gtk_menu.py b/blueprintcompiler/language/gtk_menu.py index 7569d67..707b072 100644 --- a/blueprintcompiler/language/gtk_menu.py +++ b/blueprintcompiler/language/gtk_menu.py @@ -21,10 +21,7 @@ import typing as T from blueprintcompiler.language.values import StringValue -from .attributes import BaseAttribute -from .gobject_object import Object, ObjectContent from .common import * -from .values import Translated, QuotedLiteral from .contexts import ValueTypeCtx @@ -51,14 +48,6 @@ class Menu(AstNode): raise CompileError("Menu requires an ID") -class MenuValue(AstNode): - grammar = AnyOf(QuotedLiteral, Translated) - - @property - def child(self) -> T.Union[QuotedLiteral, Translated]: - return self.children[0] - - class MenuAttribute(AstNode): tag_name = "attribute" diff --git a/blueprintcompiler/language/gtk_string_list.py b/blueprintcompiler/language/gtk_string_list.py index 73a8b8d..78d9c67 100644 --- a/blueprintcompiler/language/gtk_string_list.py +++ b/blueprintcompiler/language/gtk_string_list.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .attributes import BaseTypedAttribute from .gobject_object import ObjectContent, validate_parent_type from .values import StringValue from .common import * diff --git a/blueprintcompiler/language/gtk_styles.py b/blueprintcompiler/language/gtk_styles.py index 46e9a23..798773c 100644 --- a/blueprintcompiler/language/gtk_styles.py +++ b/blueprintcompiler/language/gtk_styles.py @@ -25,6 +25,10 @@ from .common import * class StyleClass(AstNode): grammar = UseQuoted("name") + @property + def name(self) -> str: + return self.tokens["name"] + class ExtStyles(AstNode): grammar = [ diff --git a/blueprintcompiler/language/property_binding.py b/blueprintcompiler/language/property_binding.py index 101bef5..200b271 100644 --- a/blueprintcompiler/language/property_binding.py +++ b/blueprintcompiler/language/property_binding.py @@ -20,7 +20,6 @@ from .common import * from .contexts import ScopeCtx from .gobject_object import Object -from .gtkbuilder_template import Template class PropertyBindingFlag(AstNode): diff --git a/blueprintcompiler/language/types.py b/blueprintcompiler/language/types.py index 34e9558..165f6b2 100644 --- a/blueprintcompiler/language/types.py +++ b/blueprintcompiler/language/types.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import typing as T from .common import * from ..gir import Class, ExternType, Interface diff --git a/blueprintcompiler/language/values.py b/blueprintcompiler/language/values.py index f0cc068..3204694 100644 --- a/blueprintcompiler/language/values.py +++ b/blueprintcompiler/language/values.py @@ -21,8 +21,6 @@ import typing as T from .common import * from .types import TypeName -from .property_binding import PropertyBinding -from .binding import Binding from .gobject_object import Object from .contexts import ScopeCtx, ValueTypeCtx diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index db53030..bd70e85 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -335,8 +335,8 @@ class XmlOutput(OutputFormat): elif isinstance(extension, ExtStyles): xml.start_tag("style") - for prop in extension.children: - xml.put_self_closing("class", name=prop.tokens["name"]) + for style in extension.children: + xml.put_self_closing("class", name=style.name) xml.end_tag() elif isinstance(extension, ExtSizeGroupWidgets):