mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Support Python 3.9
Remove the '|' syntax for type unions, since it's a 3.10 feature, and set mypy to check with version 3.9.
This commit is contained in:
parent
d6c6a66c15
commit
0b8012b8e1
7 changed files with 18 additions and 11 deletions
|
@ -6,7 +6,7 @@ build:
|
|||
image: registry.gitlab.gnome.org/jwestman/blueprint-compiler
|
||||
stage: build
|
||||
script:
|
||||
- mypy blueprintcompiler
|
||||
- mypy --python-version=3.9 blueprintcompiler
|
||||
- coverage run -m unittest
|
||||
- coverage report
|
||||
- coverage html
|
||||
|
|
|
@ -45,7 +45,7 @@ class Object(AstNode):
|
|||
return self.tokens["id"]
|
||||
|
||||
@property
|
||||
def class_name(self) -> ClassName | None:
|
||||
def class_name(self) -> T.Optional[ClassName]:
|
||||
return self.children[ClassName][0]
|
||||
|
||||
@property
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import typing as T
|
||||
|
||||
from .gtkbuilder_template import Template
|
||||
from .common import *
|
||||
|
@ -45,7 +46,7 @@ class Signal(AstNode):
|
|||
return self.tokens["name"]
|
||||
|
||||
@property
|
||||
def detail_name(self) -> str | None:
|
||||
def detail_name(self) -> T.Optional[str]:
|
||||
return self.tokens["detail_name"]
|
||||
|
||||
@property
|
||||
|
@ -53,7 +54,7 @@ class Signal(AstNode):
|
|||
return self.tokens["handler"]
|
||||
|
||||
@property
|
||||
def object_id(self) -> str | None:
|
||||
def object_id(self) -> T.Optional[str]:
|
||||
return self.tokens["object"]
|
||||
|
||||
@property
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import typing as T
|
||||
|
||||
from .gobject_object import Object, ObjectContent
|
||||
from .common import *
|
||||
|
@ -39,7 +40,7 @@ class Template(Object):
|
|||
return self.tokens["id"]
|
||||
|
||||
@property
|
||||
def class_name(self) -> ClassName | None:
|
||||
def class_name(self) -> T.Optional[ClassName]:
|
||||
if len(self.children[ClassName]):
|
||||
return self.children[ClassName][0]
|
||||
else:
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import typing as T
|
||||
|
||||
from .common import *
|
||||
from .types import TypeName
|
||||
|
@ -50,7 +51,7 @@ class TranslatedStringValue(Value):
|
|||
return self.tokens["value"]
|
||||
|
||||
@property
|
||||
def context(self) -> str | None:
|
||||
def context(self) -> T.Optional[str]:
|
||||
return self.tokens["context"]
|
||||
|
||||
|
||||
|
@ -116,7 +117,7 @@ class NumberValue(Value):
|
|||
grammar = UseNumber("value")
|
||||
|
||||
@property
|
||||
def value(self) -> int | float:
|
||||
def value(self) -> T.Union[int, float]:
|
||||
return self.tokens["value"]
|
||||
|
||||
@validate()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import typing as T
|
||||
|
||||
from .. import OutputFormat
|
||||
from ...language import *
|
||||
from .xml_emitter import XmlEmitter
|
||||
|
@ -45,7 +47,7 @@ class XmlOutput(OutputFormat):
|
|||
self._emit_object_or_template(obj, xml)
|
||||
xml.end_tag()
|
||||
|
||||
def _emit_object_or_template(self, obj: Object | Template, xml: XmlEmitter):
|
||||
def _emit_object_or_template(self, obj: T.Union[Object, Template], xml: XmlEmitter):
|
||||
for child in obj.content.children:
|
||||
if isinstance(child, Property):
|
||||
self._emit_property(child, xml)
|
||||
|
@ -123,7 +125,7 @@ class XmlOutput(OutputFormat):
|
|||
|
||||
def _translated_string_attrs(
|
||||
self, translated: TranslatedStringValue
|
||||
) -> T.Dict[str, str | None]:
|
||||
) -> T.Dict[str, T.Optional[str]]:
|
||||
return {
|
||||
"translatable": "true",
|
||||
"context": translated.context,
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import typing as T
|
||||
|
||||
from xml.sax import saxutils
|
||||
|
||||
from blueprintcompiler.gir import GirType
|
||||
|
@ -30,7 +32,7 @@ class XmlEmitter:
|
|||
self._tag_stack = []
|
||||
self._needs_newline = False
|
||||
|
||||
def start_tag(self, tag, **attrs: str | GirType | ClassName | bool | None):
|
||||
def start_tag(self, tag, **attrs: T.Union[str, GirType, ClassName, bool, None]):
|
||||
self._indent()
|
||||
self.result += f"<{tag}"
|
||||
for key, val in attrs.items():
|
||||
|
@ -56,7 +58,7 @@ class XmlEmitter:
|
|||
self.result += f"</{tag}>"
|
||||
self._needs_newline = True
|
||||
|
||||
def put_text(self, text: str | int | float):
|
||||
def put_text(self, text: T.Union[str, int, float]):
|
||||
self.result += saxutils.escape(str(text))
|
||||
self._needs_newline = False
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue