diff --git a/applications/generate/philadelphia/java.py b/applications/generate/philadelphia/java.py index ae20b43c..33791457 100644 --- a/applications/generate/philadelphia/java.py +++ b/applications/generate/philadelphia/java.py @@ -18,7 +18,7 @@ import typing -_TYPE_FORMATTERS: typing.Dict[str, typing.Callable[[str], str]] = { +_TYPE_FORMATTERS: dict[str, typing.Callable[[str], str]] = { 'char': lambda value: '\'' + value + '\'', 'int': str, 'String': lambda value: '"' + value + '"', @@ -31,7 +31,7 @@ class ConstantField(typing.NamedTuple): value: str -def _format_constant_fields(fields: typing.List[ConstantField]) -> str: +def _format_constant_fields(fields: list[ConstantField]) -> str: type_width = max(len(field.type_) for field in fields) name_width = max(len(field.name) for field in fields) return '\n'.join(_format_constant_field(field, type_width, name_width) @@ -48,7 +48,7 @@ def _format_constant_field(field: ConstantField, type_width: int, class InnerClass: def __init__(self, name: str, javadoc: str, - fields: typing.List[ConstantField]) -> None: + fields: list[ConstantField]) -> None: self.name = name self.javadoc = javadoc self.fields = fields @@ -81,8 +81,8 @@ def _format_fields(self) -> str: class Class: def __init__(self, name: str, javadoc: str, - classes: typing.Optional[typing.List[InnerClass]] = None, - fields: typing.Optional[typing.List[ConstantField]] = None) -> None: + classes: typing.Optional[list[InnerClass]] = None, + fields: typing.Optional[list[ConstantField]] = None) -> None: self.name = name self.javadoc = javadoc self.classes = classes if classes else [] diff --git a/applications/generate/philadelphia/model.py b/applications/generate/philadelphia/model.py index 33100958..9d07e93b 100644 --- a/applications/generate/philadelphia/model.py +++ b/applications/generate/philadelphia/model.py @@ -37,9 +37,9 @@ class Value(typing.NamedTuple): class Enumeration(typing.NamedTuple): primary_field: Field - secondary_fields: typing.List[Field] + secondary_fields: list[Field] type_: str - values: typing.List[Value] + values: list[Value] class Message(typing.NamedTuple): @@ -56,7 +56,7 @@ def read_dialect(filename: str) -> Dialect: return Dialect(package_name, class_name_prefix, name) -def format_enumerations(enumerations: typing.List[Enumeration], dialect: Dialect) -> java.CompilationUnit: +def format_enumerations(enumerations: list[Enumeration], dialect: Dialect) -> java.CompilationUnit: name = '{}Enumerations'.format(dialect.class_name_prefix) javadoc = 'Enumerations for {}.'.format(dialect.name) classes = [_format_enumeration(enumeration) for enumeration in enumerations] @@ -91,7 +91,7 @@ def _format_secondary_fields_javadoc(enumeration: Enumeration) -> typing.Optiona return '{}{}{}'.format(header, items, footer) -def format_msg_types(messages: typing.List[Message], dialect: Dialect) -> java.CompilationUnit: +def format_msg_types(messages: list[Message], dialect: Dialect) -> java.CompilationUnit: name = '{}MsgTypes'.format(dialect.class_name_prefix) javadoc = 'Message types for {}.'.format(dialect.name) fields = [_format_msg_type(message) for message in messages] @@ -103,7 +103,7 @@ def _format_msg_type(message: Message) -> java.ConstantField: return java.ConstantField(type_=type_, name=message.name, value=message.msg_type) -def format_tags(fields: typing.List[Field], dialect: Dialect) -> java.CompilationUnit: +def format_tags(fields: list[Field], dialect: Dialect) -> java.CompilationUnit: name = '{}Tags'.format(dialect.class_name_prefix) javadoc = 'Tags for {}.'.format(dialect.name) constant_fields = [_format_tag(field) for field in fields] @@ -115,7 +115,7 @@ def _format_tag(field: Field) -> java.ConstantField: def _format_constant_fields(name: str, javadoc: str, - fields: typing.List[java.ConstantField], dialect: Dialect) -> java.CompilationUnit: + fields: list[java.ConstantField], dialect: Dialect) -> java.CompilationUnit: package = java.Package(name=dialect.package_name) class_ = java.Class(name=name, javadoc=javadoc, fields=fields) return java.CompilationUnit(package, class_) diff --git a/applications/generate/philadelphia/orchestra.py b/applications/generate/philadelphia/orchestra.py index 969c696e..08d5e8c2 100644 --- a/applications/generate/philadelphia/orchestra.py +++ b/applications/generate/philadelphia/orchestra.py @@ -25,7 +25,7 @@ } -def read_messages(filename: str) -> typing.List[model.Message]: +def read_messages(filename: str) -> list[model.Message]: def message(elem: etree.Element) -> model.Message: name = etree.get(elem, 'name') msg_type = etree.get(elem, 'msgType') @@ -34,14 +34,14 @@ def message(elem: etree.Element) -> model.Message: return [message(elem) for elem in tree.findall('.//fixr:message', _NS)] -def read_fields(filename: str) -> typing.List[model.Field]: +def read_fields(filename: str) -> list[model.Field]: tree = etree.parse(filename) fields = _read_fields(tree) return sorted([_make_field(field) for field in fields], key=lambda field: int(field.tag)) -def read_enumerations(filename: str) -> typing.List[model.Enumeration]: +def read_enumerations(filename: str) -> list[model.Enumeration]: tree = etree.parse(filename) fields = _read_fields(tree) fields_by_type = _group_fields_by_type(fields) @@ -60,10 +60,10 @@ class _CodeSet(typing.NamedTuple): name: str id_: str type_: str - codes: typing.List[_Code] + codes: list[_Code] -def _read_code_sets(tree: etree.ElementTree) -> typing.List[_CodeSet]: +def _read_code_sets(tree: etree.ElementTree) -> list[_CodeSet]: def code(elem: etree.Element) -> _Code: name = etree.get(elem, 'name') value = etree.get(elem, 'value') @@ -84,7 +84,7 @@ class _Field(typing.NamedTuple): type_: str -def _read_fields(tree: etree.ElementTree) -> typing.List[_Field]: +def _read_fields(tree: etree.ElementTree) -> list[_Field]: def field(elem: etree.Element) -> _Field: id_ = etree.get(elem, 'id') name = etree.get(elem, 'name') @@ -97,7 +97,7 @@ def _make_field(field: _Field) -> model.Field: return model.Field(tag=field.id_, name=field.name) -def _make_enumeration(code_set: _CodeSet, fields: typing.List[_Field]) -> model.Enumeration: +def _make_enumeration(code_set: _CodeSet, fields: list[_Field]) -> model.Enumeration: primary_fields = [field for field in fields if code_set.id_ == field.id_] primary_field = primary_fields[0] secondary_fields = sorted([field for field in fields if code_set.id_ != field.id_], @@ -132,14 +132,14 @@ def _make_type(field: _Field, code_set: typing.Optional[_CodeSet]) -> str: } -def _make_values(code_set: _CodeSet) -> typing.List[model.Value]: +def _make_values(code_set: _CodeSet) -> list[model.Value]: def value(id_: str, code: _Code) -> model.Value: name = _NAME_REPLACEMENTS.get((id_, code.value), code.name) return model.Value(name=name, value=code.value) return [value(code_set.id_, code) for code in code_set.codes] -def _group_fields_by_type(fields: typing.List[_Field]) -> typing.Dict[str, typing.List[_Field]]: +def _group_fields_by_type(fields: list[_Field]) -> dict[str, list[_Field]]: sorted_by_type = sorted(fields, key=lambda field: field.type_) return {type_: list(grouped_by_type) for type_, grouped_by_type in itertools.groupby(sorted_by_type, lambda field: field.type_)} @@ -154,7 +154,7 @@ def _has_values(code_set: _CodeSet) -> bool: return not code_set.id_ in _NO_VALUES and not code_set.type_ == 'Boolean' -def _sorted_codes(codes: typing.List[_Code]) -> typing.List[_Code]: +def _sorted_codes(codes: list[_Code]) -> list[_Code]: if all(code.sort is not None for code in codes): return sorted(codes, key=lambda code: code.sort or 0) return codes diff --git a/applications/generate/philadelphia/quickfix.py b/applications/generate/philadelphia/quickfix.py index 5ecf7c27..39f4eb02 100644 --- a/applications/generate/philadelphia/quickfix.py +++ b/applications/generate/philadelphia/quickfix.py @@ -13,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import typing - from . import etree from . import model -def read_messages(filename: str) -> typing.List[model.Message]: +def read_messages(filename: str) -> list[model.Message]: def message(elem: etree.Element) -> model.Message: name = etree.get(elem, 'name') msgtype = etree.get(elem, 'msgtype') @@ -28,13 +26,13 @@ def message(elem: etree.Element) -> model.Message: return [message(elem) for elem in tree.findall('./messages/message')] -def read_fields(filename: str) -> typing.List[model.Field]: +def read_fields(filename: str) -> list[model.Field]: tree = etree.parse(filename) return sorted([_read_field(elem) for elem in tree.findall('./fields/field')], key=lambda field: int(field.tag)) -def read_enumerations(filename: str) -> typing.List[model.Enumeration]: +def read_enumerations(filename: str) -> list[model.Enumeration]: def enumeration(elem: etree.Element) -> model.Enumeration: field = _read_field(elem) values = _read_values(elem) @@ -61,7 +59,7 @@ def _read_field(elem: etree.Element) -> model.Field: return model.Field(tag=number, name=name) -def _read_type(elem: etree.Element, values: typing.List[model.Value]) -> str: +def _read_type(elem: etree.Element, values: list[model.Value]) -> str: type_ = _TYPES.get(etree.get(elem, 'type'), 'String') if type_ == 'char' and values and max(len(value.value) for value in values) > 1: return 'String' @@ -72,7 +70,7 @@ def _has_values(elem: etree.Element) -> bool: return etree.get(elem, 'name') != 'MsgType' and elem.find('value') is not None -def _read_values(root: etree.Element) -> typing.List[model.Value]: +def _read_values(root: etree.Element) -> list[model.Value]: def value(elem: etree.Element) -> model.Value: enum = etree.get(elem, 'enum') description = etree.get(elem, 'description') diff --git a/applications/generate/philadelphia/repository.py b/applications/generate/philadelphia/repository.py index 31ac02f4..3eb94a01 100644 --- a/applications/generate/philadelphia/repository.py +++ b/applications/generate/philadelphia/repository.py @@ -21,7 +21,7 @@ from . import model -def read_messages(dirname: str) -> typing.List[model.Message]: +def read_messages(dirname: str) -> list[model.Message]: def message(elem: etree.Element) -> model.Message: name = _find(elem, 'Name') msg_type = _find(elem, 'MsgType') @@ -31,12 +31,12 @@ def message(elem: etree.Element) -> model.Message: return [message(elem) for elem in tree.findall('Message')] -def read_fields(dirname: str) -> typing.List[model.Field]: +def read_fields(dirname: str) -> list[model.Field]: fields = _read_fields(dirname) return sorted([_make_field(field) for field in fields], key=lambda field: int(field.tag)) -def read_enumerations(dirname: str) -> typing.List[model.Enumeration]: +def read_enumerations(dirname: str) -> list[model.Enumeration]: fields = _read_fields(dirname) fields_by_tag = {field.tag: field for field in fields} enums = _read_enums(dirname) @@ -63,14 +63,14 @@ def _make_field(field: _Field) -> model.Field: return model.Field(tag=field.tag, name=field.name) -def _make_enumeration(field: _Field, enums: typing.List[_Enum]) -> model.Enumeration: +def _make_enumeration(field: _Field, enums: list[_Enum]) -> model.Enumeration: values = _make_values(enums) type_ = _make_type(field.type_, values) return model.Enumeration(primary_field=_make_field(field), secondary_fields=[], type_=type_, values=values) -def _make_values(enums: typing.List[_Enum]) -> typing.List[model.Value]: +def _make_values(enums: list[_Enum]) -> list[model.Value]: def value(enum: _Enum) -> model.Value: return model.Value(name=enum.symbolic_name, value=enum.value) return [value(enum) for enum in _sorted_enums(enums)] @@ -86,7 +86,7 @@ def value(enum: _Enum) -> model.Value: } -def _make_type(field_type: str, values: typing.List[model.Value]) -> str: +def _make_type(field_type: str, values: list[model.Value]) -> str: type_ = _TYPES.get(field_type, field_type) if type_ == 'char' and values and max(len(value.value) for value in values) > 1: return 'String' @@ -97,7 +97,7 @@ def _has_values(field: _Field) -> bool: return not field.type_ == 'Boolean' and not field.name == 'MsgType' -def _read_fields(dirname: str) -> typing.List[_Field]: +def _read_fields(dirname: str) -> list[_Field]: def field(elem: etree.Element) -> _Field: tag = _find(elem, 'Tag') name = _find(elem, 'Name') @@ -108,8 +108,8 @@ def field(elem: etree.Element) -> _Field: return [field(elem) for elem in tree.findall('Field')] -def _read_enums(dirname: str) -> typing.List[_Enum]: - def enums(elem: etree.Element) -> typing.List[_Enum]: +def _read_enums(dirname: str) -> list[_Enum]: + def enums(elem: etree.Element) -> list[_Enum]: tag = _find(elem, 'Tag') value = _read_value(elem, tag) symbolic_names = _read_symbolic_names(elem, tag, value) @@ -122,7 +122,7 @@ def enums(elem: etree.Element) -> typing.List[_Enum]: key=lambda enum: int(enum.tag)) -def _sorted_enums(enums: typing.List[_Enum]) -> typing.List[_Enum]: +def _sorted_enums(enums: list[_Enum]) -> list[_Enum]: if all(enum.sort is not None for enum in enums): return sorted(enums, key=lambda enum: enum.sort or 0) return enums @@ -159,7 +159,7 @@ def _read_sort(root: etree.Element) -> typing.Optional[int]: } -def _read_symbolic_names(elem: etree.Element, tag: str, value: str) -> typing.List[str]: +def _read_symbolic_names(elem: etree.Element, tag: str, value: str) -> list[str]: symbolic_name = _find(elem, 'SymbolicName') primary = _SYMBOLIC_NAMES.get((tag, value), symbolic_name) aliases = _SYMBOLIC_NAME_ALIASES.get((tag, value), []) diff --git a/applications/generate/philadelphia/source.py b/applications/generate/philadelphia/source.py index 41c1bc8d..13b54433 100644 --- a/applications/generate/philadelphia/source.py +++ b/applications/generate/philadelphia/source.py @@ -20,11 +20,11 @@ class Source(typing.Protocol): - def read_enumerations(self, filename: str) -> typing.List[model.Enumeration]: + def read_enumerations(self, filename: str) -> list[model.Enumeration]: ... - def read_fields(self, filename: str) -> typing.List[model.Field]: + def read_fields(self, filename: str) -> list[model.Field]: ... - def read_messages(self, filename: str) -> typing.List[model.Message]: + def read_messages(self, filename: str) -> list[model.Message]: ...