From e978ee04d7a6ca628a2ad5ed1d955a53747a0a15 Mon Sep 17 00:00:00 2001 From: timrid <6593626+timrid@users.noreply.github.com> Date: Mon, 27 Jul 2026 08:29:20 +0200 Subject: [PATCH] Remove unnecessary quotes in type annotations --- construct_editor/core/__init__.py | 1 - construct_editor/core/callbacks.py | 3 +- construct_editor/core/commands.py | 3 +- construct_editor/core/construct_editor.py | 35 +- construct_editor/core/context_menu.py | 11 +- construct_editor/core/custom.py | 23 +- construct_editor/core/entries.py | 303 +++++++++--------- construct_editor/core/model.py | 33 +- construct_editor/core/preprocessor.py | 9 +- construct_editor/gallery/__init__.py | 4 +- construct_editor/gallery/example_cmd_resp.py | 2 + construct_editor/gallery/example_ipstack.py | 2 + construct_editor/gallery/example_pe32coff.py | 2 + construct_editor/gallery/test_aligned.py | 2 + construct_editor/gallery/test_array.py | 2 + .../gallery/test_bits_swapped_bitwise.py | 2 + construct_editor/gallery/test_bitwise.py | 2 + .../gallery/test_bytes_greedybytes.py | 2 + construct_editor/gallery/test_checksum.py | 2 + construct_editor/gallery/test_compressed.py | 2 + construct_editor/gallery/test_computed.py | 2 + construct_editor/gallery/test_const.py | 2 + .../gallery/test_dataclass_bit_struct.py | 2 + .../gallery/test_dataclass_struct.py | 2 + construct_editor/gallery/test_default.py | 2 + construct_editor/gallery/test_enum.py | 2 + construct_editor/gallery/test_fixedsized.py | 2 + construct_editor/gallery/test_flag.py | 2 + construct_editor/gallery/test_flagsenum.py | 2 + construct_editor/gallery/test_focusedseq.py | 2 + construct_editor/gallery/test_greedyrange.py | 2 + construct_editor/gallery/test_ifthenelse.py | 2 + .../gallery/test_ifthenelse_nested_switch.py | 2 + construct_editor/gallery/test_nullstripped.py | 2 + .../gallery/test_nullterminated.py | 2 + construct_editor/gallery/test_padded.py | 2 + .../gallery/test_padded_string.py | 2 + construct_editor/gallery/test_pass.py | 2 + .../gallery/test_pointer_peek_seek_tell.py | 2 + construct_editor/gallery/test_renamed.py | 2 + construct_editor/gallery/test_select.py | 2 + .../gallery/test_select_complex.py | 2 + .../gallery/test_stringencodded.py | 2 + construct_editor/gallery/test_switch.py | 2 + .../gallery/test_switch_dataclass.py | 8 +- construct_editor/gallery/test_tenum.py | 2 + construct_editor/gallery/test_tflagsenum.py | 2 + construct_editor/gallery/test_timestamp.py | 2 + construct_editor/main.py | 2 + .../wx_widgets/wx_construct_editor.py | 7 +- .../wx_widgets/wx_construct_hex_editor.py | 5 +- .../wx_widgets/wx_context_menu.py | 9 +- .../wx_widgets/wx_exception_dialog.py | 2 + construct_editor/wx_widgets/wx_hex_editor.py | 17 +- construct_editor/wx_widgets/wx_obj_view.py | 18 +- .../wx_widgets/wx_python_code_editor.py | 2 +- pyproject.toml | 1 + 57 files changed, 328 insertions(+), 242 deletions(-) diff --git a/construct_editor/core/__init__.py b/construct_editor/core/__init__.py index 40a96af..e69de29 100644 --- a/construct_editor/core/__init__.py +++ b/construct_editor/core/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/construct_editor/core/callbacks.py b/construct_editor/core/callbacks.py index d6ff559..c9e26bf 100644 --- a/construct_editor/core/callbacks.py +++ b/construct_editor/core/callbacks.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + from typing import Callable, Generic, TypeVar from typing_extensions import ParamSpec diff --git a/construct_editor/core/commands.py b/construct_editor/core/commands.py index 421f751..8f8e47e 100644 --- a/construct_editor/core/commands.py +++ b/construct_editor/core/commands.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import abc import typing as t diff --git a/construct_editor/core/construct_editor.py b/construct_editor/core/construct_editor.py index 840eda1..d87360a 100644 --- a/construct_editor/core/construct_editor.py +++ b/construct_editor/core/construct_editor.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import annotations import abc @@ -19,7 +18,7 @@ def __init__(self, construct: cs.Construct[t.Any, t.Any], model: ConstructEditor self.change_construct(construct) self.on_entry_selected: CallbackList[ - ["entries.EntryConstruct"] + [entries.EntryConstruct] ] = CallbackList() self.on_root_obj_changed: CallbackList[[t.Any]] = CallbackList() @@ -56,7 +55,7 @@ def show_status(self, path_info: str, bytes_info: str): """ @abc.abstractmethod - def get_selected_entry(self) -> "entries.EntryConstruct | None": + def get_selected_entry(self) -> entries.EntryConstruct | None: """ Get the currently selected entry (or None if nothing is selected). @@ -64,7 +63,7 @@ def get_selected_entry(self) -> "entries.EntryConstruct | None": """ @abc.abstractmethod - def select_entry(self, entry: "entries.EntryConstruct") -> None: + def select_entry(self, entry: entries.EntryConstruct) -> None: """ Select an entry programmatically. @@ -87,21 +86,21 @@ def _get_from_clipboard(self) -> str | None: This has to be implemented by the derived class. """ - def copy_entry_value_to_clipboard(self, entry: "entries.EntryConstruct"): + def copy_entry_value_to_clipboard(self, entry: entries.EntryConstruct): """ Copy the value of the entry to the clipboard. """ copy_txt = entry.obj_str self._put_to_clipboard(copy_txt) - def copy_entry_path_to_clipboard(self, entry: "entries.EntryConstruct"): + def copy_entry_path_to_clipboard(self, entry: entries.EntryConstruct): """ Copy the path of the entry to the clipboard. """ copy_txt = entries.create_path_str(entry.path) self._put_to_clipboard(copy_txt) - def paste_entry_value_from_clipboard(self, entry: "entries.EntryConstruct"): + def paste_entry_value_from_clipboard(self, entry: entries.EntryConstruct): """ Paste the value of the entry from the clipboard. """ @@ -182,14 +181,14 @@ def build(self, **contextkw: t.Any) -> bytes: return binary @abc.abstractmethod - def expand_entry(self, entry: "entries.EntryConstruct"): + def expand_entry(self, entry: entries.EntryConstruct): """ Expand an entry. This has to be implemented by the derived class. """ - def expand_children(self, entry: "entries.EntryConstruct"): + def expand_children(self, entry: entries.EntryConstruct): """ Expand all children of an entry recursively including the entry itself. """ @@ -212,7 +211,7 @@ def expand_level(self, level: int): Expand all Entries to Level ... (0=root level) """ - def dvc_expand(entry: "entries.EntryConstruct", current_level: int): + def dvc_expand(entry: entries.EntryConstruct, current_level: int): subentries = entry.subentries if subentries is None: return @@ -227,14 +226,14 @@ def dvc_expand(entry: "entries.EntryConstruct", current_level: int): dvc_expand(self._model.root_entry, 1) @abc.abstractmethod - def collapse_entry(self, entry: "entries.EntryConstruct"): + def collapse_entry(self, entry: entries.EntryConstruct): """ Collapse an entry. This has to be implemented by the derived class. """ - def collapse_children(self, entry: "entries.EntryConstruct"): + def collapse_children(self, entry: entries.EntryConstruct): """ Collapse all children of an entry recursively including the entry itself. """ @@ -252,7 +251,7 @@ def collapse_all(self): if self._model.root_entry: self.collapse_children(self._model.root_entry) - def restore_expansion_from_model(self, entry: "entries.EntryConstruct"): + def restore_expansion_from_model(self, entry: entries.EntryConstruct): """ Restore the expansion state from the model recursively. @@ -277,7 +276,7 @@ def restore_expansion_from_model(self, entry: "entries.EntryConstruct"): for subentry in subentries: self.restore_expansion_from_model(subentry) - def enable_list_view(self, entry: "entries.EntryConstruct"): + def enable_list_view(self, entry: entries.EntryConstruct): """ Enable the list view for an entry. """ @@ -292,7 +291,7 @@ def enable_list_view(self, entry: "entries.EntryConstruct"): self.collapse_children(entry) self.expand_entry(entry) - def disable_list_view(self, entry: "entries.EntryConstruct"): + def disable_list_view(self, entry: entries.EntryConstruct): """ Disable the list view for an entry. """ @@ -302,7 +301,7 @@ def disable_list_view(self, entry: "entries.EntryConstruct"): self._model.list_viewed_entries.remove(entry) self.reload() - def is_list_view_enabled(self, entry: "entries.EntryConstruct") -> bool: + def is_list_view_enabled(self, entry: entries.EntryConstruct) -> bool: """ Check if an entry is shown in a list view. """ @@ -362,7 +361,7 @@ def _get_list_viewed_column_count(self): return column_count def _get_list_viewed_column_names( - self, selected_entry: "entries.EntryConstruct" + self, selected_entry: entries.EntryConstruct ) -> t.List[str]: """ Get the names of all list viewed columns. @@ -381,7 +380,7 @@ def _get_list_viewed_column_names( column_names.append(entries.create_path_str(column_path)) return column_names - def _refresh_status_bar(self, entry: "entries.EntryConstruct | None") -> None: + def _refresh_status_bar(self, entry: entries.EntryConstruct | None) -> None: if entry is None: self.show_status("", "") return diff --git a/construct_editor/core/context_menu.py b/construct_editor/core/context_menu.py index cea410d..0cdfaa8 100644 --- a/construct_editor/core/context_menu.py +++ b/construct_editor/core/context_menu.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import abc import dataclasses import typing as t @@ -54,7 +55,7 @@ class RadioGroupMenuItems: @dataclasses.dataclass class SubmenuItem: label: str - subitems: t.List["MenuItem"] + subitems: t.List[MenuItem] MenuItem = ButtonMenuItem | SeparatorMenuItem | CheckboxMenuItem | RadioGroupMenuItems | SubmenuItem @@ -63,9 +64,9 @@ class SubmenuItem: class ContextMenu: def __init__( self, - parent: "construct_editor.ConstructEditor", - model: "ConstructEditorModel", - entry: t.Optional["entries.EntryConstruct"], + parent: construct_editor.ConstructEditor, + model: ConstructEditorModel, + entry: entries.EntryConstruct | None, ): self.parent = parent self.model = model diff --git a/construct_editor/core/custom.py b/construct_editor/core/custom.py index c056b97..6b12c3a 100644 --- a/construct_editor/core/custom.py +++ b/construct_editor/core/custom.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import enum import typing as t @@ -9,7 +11,7 @@ def add_custom_transparent_subconstruct( - subconstruct: t.Type["cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]"], + subconstruct: t.Type[cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]], ): """ Add compatibility of an custom `cs.Subconstruct` to the construct-editor. @@ -19,7 +21,7 @@ def add_custom_transparent_subconstruct( def add_custom_tunnel( - tunnel: t.Type["cs.Tunnel[t.Any, t.Any]"], + tunnel: t.Type[cs.Tunnel[t.Any, t.Any]], type_str: str, ): """ @@ -29,9 +31,9 @@ def add_custom_tunnel( class EntryTunnel(entries.EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: t.Optional["entries.EntryConstruct"], - construct: "cs.Compressed[t.Any, t.Any]", + model: model.ConstructEditorModel, + parent: entries.EntryConstruct | None, + construct: cs.Compressed[t.Any, t.Any], name: entries.NameType, docs: str, ): @@ -51,10 +53,7 @@ class AdapterObjEditorType(enum.Enum): def add_custom_adapter( - adapter: t.Union[ - t.Type["cs.Adapter[t.Any,t.Any,t.Any, t.Any]"], # for cs.Adapter - "cs.Adapter[t.Any,t.Any,t.Any, t.Any]", # for cs.ExprAdapter - ], + adapter: t.Type[cs.Adapter[t.Any, t.Any, t.Any, t.Any]] | cs.Adapter[t.Any, t.Any, t.Any, t.Any], type_str: str, obj_editor_type: AdapterObjEditorType, ): @@ -65,9 +64,9 @@ def add_custom_adapter( class EntryAdapter(entries.EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: t.Optional["entries.EntryConstruct"], - construct: "cs.Subconstruct[t.Any, t.Any, t.Any, t.Any]", + model: model.ConstructEditorModel, + parent: entries.EntryConstruct | None, + construct: cs.Subconstruct[t.Any, t.Any, t.Any, t.Any], name: entries.NameType, docs: str, ): diff --git a/construct_editor/core/entries.py b/construct_editor/core/entries.py index 1954eee..fb655e4 100644 --- a/construct_editor/core/entries.py +++ b/construct_editor/core/entries.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import dataclasses import io import string import typing as t -from typing import Any, Dict, List, Optional, Type +from typing import Any, Dict, List, Type import construct as cs import construct_typed as cst @@ -26,7 +27,7 @@ def evaluate(param, context): return param(context) if callable(param) else param -def int_to_str(integer_format: "model.IntegerFormat", val: int) -> str: +def int_to_str(integer_format: model.IntegerFormat, val: int) -> str: if isinstance(val, str): return val # tolerate string if integer_format is model.IntegerFormat.Hex: @@ -51,42 +52,42 @@ def str_to_bytes(s: str) -> bytes: @dataclasses.dataclass class ObjViewSettings_Default: - entry: "EntryConstruct" + entry: EntryConstruct @dataclasses.dataclass class ObjViewSettings_String: - entry: "EntryConstruct" + entry: EntryConstruct @dataclasses.dataclass class ObjViewSettings_Integer: - entry: "EntryConstruct" + entry: EntryConstruct @dataclasses.dataclass class ObjViewSettings_Flag: - entry: "EntryConstruct" + entry: EntryConstruct @dataclasses.dataclass class ObjViewSettings_Bytes: - entry: "EntryConstruct" + entry: EntryConstruct @dataclasses.dataclass class ObjViewSettings_Enum: - entry: t.Union["EntryEnum", "EntryTEnum"] + entry: EntryEnum | EntryTEnum @dataclasses.dataclass class ObjViewSettings_FlagsEnum: - entry: t.Union["EntryFlagsEnum", "EntryTFlagsEnum"] + entry: EntryFlagsEnum | EntryTFlagsEnum @dataclasses.dataclass class ObjViewSettings_Timestamp: - entry: "EntryTimestamp" + entry: EntryTimestamp ObjViewSettings = ( @@ -194,9 +195,9 @@ def create_path_str(path: PathType) -> str: class EntryConstruct(object): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Construct[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Construct[Any, Any], name: NameType | None, docs: str, ): @@ -233,12 +234,12 @@ def get_debug_infos(self) -> str: # default "parent" ######################################################## @property - def parent(self) -> Optional["EntryConstruct"]: + def parent(self) -> EntryConstruct | None: return self._parent # default "construct" ##################################################### @property - def construct(self) -> "cs.Construct[Any, Any]": + def construct(self) -> cs.Construct[Any, Any]: return self._construct # default "obj" ########################################################### @@ -298,7 +299,7 @@ def typ_str(self) -> str: # default "subentries" #################################################### @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: return None # default "visible_row" ################################################### @@ -311,7 +312,7 @@ def visible_row(self, val: bool): self._visible_row = val # default "get_visible_row_entry" ######################################### - def get_visible_row_entry(self) -> t.Optional["EntryConstruct"]: + def get_visible_row_entry(self) -> EntryConstruct | None: """ Get the entry that represents the visible row. If this is not an visible row, iterate throud all parents till we find @@ -411,9 +412,9 @@ def get_stream_infos( class EntrySubconstruct(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Subconstruct[Any, Any, Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Subconstruct[Any, Any, Any, Any], name: NameType | None, docs: str, ): @@ -435,7 +436,7 @@ def typ_str(self) -> str: # pass throught "subentries" to subentry ################################## @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: return self.subentry.subentries # pass throught "obj_view_settings" to subentry ########################### @@ -452,9 +453,9 @@ def modify_context_menu(self, menu: ContextMenu): class EntryStruct(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Struct", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Struct, name: NameType | None, docs: str, ): @@ -469,11 +470,11 @@ def __init__( self._subentries.append(subentry) @property - def construct(self) -> "cs.Struct": + def construct(self) -> cs.Struct: return t.cast("cs.Struct", self._construct) @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: return self._subentries @property @@ -518,9 +519,9 @@ def on_collapse_children_clicked(): class EntryArray(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Array[Any, Any] | cs.GreedyRange[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Array[Any, Any] | cs.GreedyRange[Any, Any], name: NameType | None, docs: str, ): @@ -529,11 +530,11 @@ def __init__( self._subentries: list[EntryConstruct] = [] @property - def construct(self) -> "cs.Array[Any, Any] | cs.GreedyRange[Any, Any]": + def construct(self) -> cs.Array[Any, Any] | cs.GreedyRange[Any, Any]: return t.cast("cs.Array[Any, Any] | cs.GreedyRange[Any, Any]", self._construct) @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: # get length of array try: array_len = len(self.obj) @@ -633,9 +634,9 @@ def on_menu_item_clicked(checked: bool): class EntryIfThenElse(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.IfThenElse[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.IfThenElse[Any, Any], name: NameType | None, docs: str, ): @@ -664,10 +665,10 @@ def __init__( ] @property - def construct(self) -> "cs.IfThenElse[Any, Any]": + def construct(self) -> cs.IfThenElse[Any, Any]: return t.cast("cs.IfThenElse[Any, Any]", self._construct) - def _get_subentry(self) -> "EntryConstruct | None": + def _get_subentry(self) -> EntryConstruct | None: """Evaluate the conditional function to detect the type of the subentry""" obj = self.obj if obj is None: @@ -701,7 +702,7 @@ def typ_str(self) -> str: return subentry.typ_str @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: subentry = self._get_subentry() if subentry is None: return self._subentries @@ -728,9 +729,9 @@ def modify_context_menu(self, menu: ContextMenu): class EntrySwitch(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Switch[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Switch[Any, Any], name: NameType | None, docs: str, ): @@ -762,10 +763,10 @@ def __init__( self._subentries.append(self._subentry_default) @property - def construct(self) -> "cs.Switch[Any, Any]": + def construct(self) -> cs.Switch[Any, Any]: return t.cast("cs.Switch[Any, Any]", self._construct) - def _get_subentry(self) -> "EntryConstruct | None": + def _get_subentry(self) -> EntryConstruct | None: """Evaluate the conditional function to detect the type of the subentry""" obj = self.obj if obj is None: @@ -799,7 +800,7 @@ def typ_str(self) -> str: return subentry.typ_str @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: subentry = self._get_subentry() if subentry is None: return self._subentries @@ -874,9 +875,9 @@ class EntryFormatField(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.FormatField[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.FormatField[Any, Any], name: NameType | None, docs: str, ): @@ -888,7 +889,7 @@ def __init__( self.type_infos = self.type_mapping[construct.fmtstr] @property - def construct(self) -> "cs.FormatField[Any, Any]": + def construct(self) -> cs.FormatField[Any, Any]: return t.cast("cs.FormatField[Any, Any]", self._construct) @property @@ -922,16 +923,16 @@ def typ_str(self) -> str: class EntryBytesInteger(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.BytesInteger", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.BytesInteger, name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.BytesInteger": + def construct(self) -> cs.BytesInteger: return t.cast("cs.BytesInteger", self._construct) @property @@ -970,16 +971,16 @@ def obj_view_settings(self) -> ObjViewSettings: class EntryBitsInteger(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.BitsInteger", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.BitsInteger, name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.BitsInteger": + def construct(self) -> cs.BitsInteger: return t.cast("cs.BitsInteger", self._construct) @property @@ -1010,9 +1011,9 @@ def obj_view_settings(self) -> ObjViewSettings: class EntryStringEncoded(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.StringEncoded", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.StringEncoded, name: NameType | None, docs: str, ): @@ -1031,9 +1032,9 @@ def obj_view_settings(self) -> ObjViewSettings: class EntryBytes(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Bytes | cs.Construct[bytes, bytes]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Bytes | cs.Construct[bytes, bytes], name: NameType | None, docs: str, ): @@ -1041,7 +1042,7 @@ def __init__( self.ascii_view = False @property - def construct(self) -> "cs.Bytes | cs.Construct[bytes, bytes]": + def construct(self) -> cs.Bytes | cs.Construct[bytes, bytes]: return t.cast("cs.Bytes | cs.Construct[bytes, bytes]", self._construct) @property @@ -1096,9 +1097,9 @@ def on_ascii_view_clicked(checked: bool): class EntryTell(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Construct[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Construct[Any, Any], name: NameType | None, docs: str, ): @@ -1113,16 +1114,16 @@ def typ_str(self) -> str: class EntrySeek(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Seek", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Seek, name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.Seek": + def construct(self) -> cs.Seek: return t.cast("cs.Seek", self._construct) @property @@ -1138,9 +1139,9 @@ def obj_str(self) -> str: class EntryPass(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Construct[None, None]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Construct[None, None], name: NameType | None, docs: str, ): @@ -1159,9 +1160,9 @@ def obj_str(self) -> str: class EntryConst(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Const[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Const[Any, Any], name: NameType | None, docs: str, ): @@ -1176,9 +1177,9 @@ def obj_view_settings(self) -> ObjViewSettings: class EntryComputed(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Computed[Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Computed[Any], name: NameType | None, docs: str, ): @@ -1200,9 +1201,9 @@ def obj_str(self) -> str: class EntryDefault(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Subconstruct[Any, Any, Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Subconstruct[Any, Any, Any, Any], name: NameType | None, docs: str, ): @@ -1229,9 +1230,9 @@ def on_default_clicked(): class EntryFocusedSeq(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.FocusedSeq", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.FocusedSeq, name: NameType | None, docs: str, ): @@ -1261,10 +1262,10 @@ def __init__( self._subentries[name] = subentry @property - def construct(self) -> "cs.FocusedSeq": + def construct(self) -> cs.FocusedSeq: return t.cast("cs.FocusedSeq", self._construct) - def _get_subentry(self) -> "EntryConstruct | None": + def _get_subentry(self) -> EntryConstruct | None: """Evaluate the conditional function to detect the type of the subentry""" obj = self.obj if obj is None: @@ -1296,7 +1297,7 @@ def typ_str(self) -> str: return subentry.typ_str @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: subentry = self._get_subentry() if subentry is None: return list(self._subentries.values()) @@ -1323,9 +1324,9 @@ def modify_context_menu(self, menu: ContextMenu): class EntrySelect(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Select", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Select, name: NameType | None, docs: str, ): @@ -1346,10 +1347,10 @@ def __init__( self._subentries[id(subentry.construct)] = subentry @property - def construct(self) -> "cs.Select": + def construct(self) -> cs.Select: return t.cast("cs.Select", self._construct) - def _get_subentry(self) -> "EntryConstruct | None": + def _get_subentry(self) -> EntryConstruct | None: """Evaluate the conditional function to detect the type of the subentry""" obj = self.obj if obj is None: @@ -1386,7 +1387,7 @@ def typ_str(self) -> str: return subentry.typ_str @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: subentry = self._get_subentry() if subentry is None: return list(self._subentries.values()) @@ -1413,9 +1414,9 @@ def modify_context_menu(self, menu: ContextMenu): class EntryTimestamp(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.TimestampAdapter[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.TimestampAdapter[Any, Any], name: NameType | None, docs: str, ): @@ -1434,9 +1435,9 @@ def obj_view_settings(self) -> ObjViewSettings: class EntryTransparentSubcon(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Subconstruct[Any, Any, Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Subconstruct[Any, Any, Any, Any], name: NameType | None, docs: str, ): @@ -1447,16 +1448,16 @@ def __init__( class EntryNullStripped(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.NullStripped[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.NullStripped[Any, Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.NullStripped[Any, Any]": + def construct(self) -> cs.NullStripped[Any, Any]: return t.cast("cs.NullStripped[Any, Any]", self._construct) @property @@ -1468,16 +1469,16 @@ def typ_str(self) -> str: class EntryNullTerminated(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.NullTerminated[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.NullTerminated[Any, Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.NullTerminated[Any, Any]": + def construct(self) -> cs.NullTerminated[Any, Any]: return t.cast("cs.NullTerminated[Any, Any]", self._construct) @property @@ -1489,9 +1490,9 @@ def typ_str(self) -> str: class EntryChecksumSubcon(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Checksum[Any, Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Checksum[Any, Any, Any], name: NameType | None, docs: str, ): @@ -1508,9 +1509,9 @@ def __init__( class EntryCompressed(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Compressed[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Compressed[Any, Any], name: NameType | None, docs: str, ): @@ -1525,16 +1526,16 @@ def typ_str(self) -> str: class EntryPeek(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Peek[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Peek[Any, Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.Peek[Any, Any]": + def construct(self) -> cs.Peek[Any, Any]: return t.cast("cs.Peek[Any, Any]", self._construct) @@ -1542,9 +1543,9 @@ def construct(self) -> "cs.Peek[Any, Any]": class EntryRawCopy(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.RawCopy[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.RawCopy[Any, Any], name: NameType | None, docs: str, ): @@ -1557,20 +1558,20 @@ def __init__( class EntryDataclassStruct(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cst.DataclassStruct[Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cst.DataclassStruct[Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cst.DataclassStruct[Any]": + def construct(self) -> cst.DataclassStruct[Any]: return t.cast("cst.DataclassStruct[Any]", self._construct) @property - def subentries(self) -> List["EntryConstruct"] | None: + def subentries(self) -> List[EntryConstruct] | None: subentries = super().subentries if (subentries is not None) and self.construct.reverse: return list(reversed(subentries)) @@ -1585,16 +1586,16 @@ def typ_str(self) -> str: class EntryFlag(EntryConstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.FormatField[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.FormatField[Any, Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.FormatField[Any, Any]": + def construct(self) -> cs.FormatField[Any, Any]: return t.cast("cs.FormatField[Any, Any]", self._construct) @property @@ -1615,16 +1616,16 @@ def typ_str(self) -> str: class EntryEnum(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.Enum", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.Enum, name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.Enum": + def construct(self) -> cs.Enum: return t.cast("cs.Enum", self._construct) @property @@ -1683,16 +1684,16 @@ def conv_str_to_obj(self, s: str) -> Any: class EntryFlagsEnum(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cs.FlagsEnum", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cs.FlagsEnum, name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cs.FlagsEnum": + def construct(self) -> cs.FlagsEnum: return t.cast("cs.FlagsEnum", self._construct) @property @@ -1749,16 +1750,16 @@ def get_enum_name(e: cst.EnumBase): class EntryTEnum(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cst.TEnum[Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cst.TEnum[Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cst.TEnum[Any]": + def construct(self) -> cst.TEnum[Any]: return t.cast("cst.TEnum[Any]", self._construct) @property @@ -1809,16 +1810,16 @@ def conv_str_to_obj(self, s: str) -> Any: class EntryTFlagsEnum(EntrySubconstruct): def __init__( self, - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - construct: "cst.TFlagsEnum[Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + construct: cst.TFlagsEnum[Any], name: NameType | None, docs: str, ): super().__init__(model, parent, construct, name, docs) @property - def construct(self) -> "cst.TFlagsEnum[Any]": + def construct(self) -> cst.TFlagsEnum[Any]: return t.cast("cst.TFlagsEnum[Any]", self._construct) @property @@ -1874,7 +1875,7 @@ def conv_flagsenum_items_to_obj(self, items: t.List[FlagsEnumItem]) -> Any: # Entry Mapping ####################################################################################################### # ##################################################################################################################### construct_entry_mapping: t.Dict[ - t.Union[Type["cs.Construct[Any, Any]"], "cs.Construct[Any, Any]"], + Type[cs.Construct[Any, Any]] | cs.Construct[Any, Any], Type[EntryConstruct], ] = { # ######################################################################### @@ -1989,12 +1990,12 @@ def conv_flagsenum_items_to_obj(self, items: t.List[FlagsEnumItem]) -> Any: def create_entry_from_construct( - model: "model.ConstructEditorModel", - parent: Optional["EntryConstruct"], - subcon: "cs.Construct[Any, Any]", + model: model.ConstructEditorModel, + parent: EntryConstruct | None, + subcon: cs.Construct[Any, Any], name: NameType | None, docs: str, -) -> "EntryConstruct": +) -> EntryConstruct: # Process and then skip Renamed, to fasten up large arrays if isinstance(subcon, cs.Renamed): diff --git a/construct_editor/core/model.py b/construct_editor/core/model.py index 4463915..bfe2aae 100644 --- a/construct_editor/core/model.py +++ b/construct_editor/core/model.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import abc import enum import typing as t @@ -21,7 +22,7 @@ class ConstructEditorColumn(enum.IntEnum): class ChangeValueCmd(Command): def __init__( - self, entry: "entries.EntryConstruct", old_value: t.Any, new_value: t.Any + self, entry: entries.EntryConstruct, old_value: t.Any, new_value: t.Any ) -> None: super().__init__(True, f"Value '{entry.path[-1]}' changed") self.entry = entry @@ -49,7 +50,7 @@ class ConstructEditorModel: """ def __init__(self): - self.root_entry: "entries.EntryConstruct | None" = None + self.root_entry: entries.EntryConstruct | None = None self.root_obj: t.Any | None = None # Modelwide flag, if hidden entries should be shown (hidden means starting with an underscore) @@ -59,18 +60,18 @@ def __init__(self): self.integer_format = IntegerFormat.Dec # List with all entries that have the list view enabled - self.list_viewed_entries: t.List["entries.EntryConstruct"] = [] + self.list_viewed_entries: t.List[entries.EntryConstruct] = [] self.command_processor = CommandProcessor(max_commands=10) @abc.abstractmethod - def on_value_changed(self, entry: "entries.EntryConstruct"): + def on_value_changed(self, entry: entries.EntryConstruct): """Implement this in the derived class""" ... def get_children( - self, entry: t.Optional["entries.EntryConstruct"] - ) -> t.List["entries.EntryConstruct"]: + self, entry: entries.EntryConstruct | None + ) -> t.List[entries.EntryConstruct]: """ Get all children of an entry """ @@ -98,15 +99,15 @@ def get_children( subentry.visible_row = True return children - def is_container(self, entry: "entries.EntryConstruct") -> bool: + def is_container(self, entry: entries.EntryConstruct) -> bool: """ Check if an entry is a container (contains children) """ return entry.subentries is not None def get_parent( - self, entry: t.Optional["entries.EntryConstruct"] - ) -> t.Optional["entries.EntryConstruct"]: + self, entry: entries.EntryConstruct | None + ) -> entries.EntryConstruct | None: """ Get the parent of an entry """ @@ -127,7 +128,7 @@ def get_parent( # get the visible row entry of the parent return parent.get_visible_row_entry() - def get_value(self, entry: "entries.EntryConstruct", column: int): + def get_value(self, entry: entries.EntryConstruct, column: int): """ Return the value to be displayed for this entry in a specific column. """ @@ -144,7 +145,7 @@ def get_value(self, entry: "entries.EntryConstruct", column: int): # flatten the hierarchical structure to a list column = column - len(ConstructEditorColumn) - flat_subentry_list: t.List["entries.EntryConstruct"] = [] + flat_subentry_list: t.List[entries.EntryConstruct] = [] flat_subentry_list = self.create_flat_subentry_list(entry) if len(flat_subentry_list) > column: return flat_subentry_list[column].obj_str @@ -152,7 +153,7 @@ def get_value(self, entry: "entries.EntryConstruct", column: int): return "" def set_value( - self, new_value: t.Any, entry: "entries.EntryConstruct", column: int + self, new_value: t.Any, entry: entries.EntryConstruct, column: int ) -> None: """ Set the value of an entry. @@ -172,12 +173,12 @@ def set_value( self.command_processor.submit(cmd) def create_flat_subentry_list( - self, entry: "entries.EntryConstruct" - ) -> t.List["entries.EntryConstruct"]: + self, entry: entries.EntryConstruct + ) -> t.List[entries.EntryConstruct]: """ Create a flat list with all subentires, recursively. """ - flat_subentry_list: t.List["entries.EntryConstruct"] = [] + flat_subentry_list: t.List[entries.EntryConstruct] = [] childs = self.get_children(entry) diff --git a/construct_editor/core/preprocessor.py b/construct_editor/core/preprocessor.py index f87e8b9..bc97206 100644 --- a/construct_editor/core/preprocessor.py +++ b/construct_editor/core/preprocessor.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import copy import enum import io @@ -14,7 +15,7 @@ class GuiMetaData(t.TypedDict): construct: cst.Construct[t.Any, t.Any] context: cst.Context stream: io.BytesIO - child_gui_metadata: t.Optional["GuiMetaData"] + child_gui_metadata: GuiMetaData | None class IntWithGuiMetadata(int): @@ -131,8 +132,8 @@ def __getattr__(self, name): # ############################################################################# def include_metadata( - constr: "cs.Construct[t.Any, t.Any]", bitwise: bool = False -) -> "cs.Construct[t.Any, t.Any]": + constr: cs.Construct[t.Any, t.Any], bitwise: bool = False +) -> cs.Construct[t.Any, t.Any]: """ Surrond all named entries of a construct with offsets, so that we know the offset in the byte-stream and the length diff --git a/construct_editor/gallery/__init__.py b/construct_editor/gallery/__init__.py index 1d53228..9aacd9a 100644 --- a/construct_editor/gallery/__init__.py +++ b/construct_editor/gallery/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import typing as t @@ -6,6 +8,6 @@ @dataclasses.dataclass class GalleryItem: - construct: "cs.Construct[t.Any, t.Any]" + construct: cs.Construct[t.Any, t.Any] contextkw: t.Dict[str, t.Any] = dataclasses.field(default_factory=dict) example_binarys: t.Dict[str, bytes] = dataclasses.field(default_factory=dict) diff --git a/construct_editor/gallery/example_cmd_resp.py b/construct_editor/gallery/example_cmd_resp.py index 8292dcc..f61f439 100644 --- a/construct_editor/gallery/example_cmd_resp.py +++ b/construct_editor/gallery/example_cmd_resp.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import typing as t diff --git a/construct_editor/gallery/example_ipstack.py b/construct_editor/gallery/example_ipstack.py index f55e400..2305aba 100644 --- a/construct_editor/gallery/example_ipstack.py +++ b/construct_editor/gallery/example_ipstack.py @@ -3,6 +3,8 @@ WARNING: before parsing the application layer over a TCP stream, you must first combine all the TCP frames into a stream. See utils.tcpip for some solutions. """ +from __future__ import annotations + import typing as t import construct_typed as cst diff --git a/construct_editor/gallery/example_pe32coff.py b/construct_editor/gallery/example_pe32coff.py index f3c87f8..7fa39b9 100644 --- a/construct_editor/gallery/example_pe32coff.py +++ b/construct_editor/gallery/example_pe32coff.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from construct import * # type: ignore from . import GalleryItem diff --git a/construct_editor/gallery/test_aligned.py b/construct_editor/gallery/test_aligned.py index 1a5d8b3..986f0b2 100644 --- a/construct_editor/gallery/test_aligned.py +++ b/construct_editor/gallery/test_aligned.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_array.py b/construct_editor/gallery/test_array.py index a2915c2..fc139ab 100644 --- a/construct_editor/gallery/test_array.py +++ b/construct_editor/gallery/test_array.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import typing as t diff --git a/construct_editor/gallery/test_bits_swapped_bitwise.py b/construct_editor/gallery/test_bits_swapped_bitwise.py index 5515aa4..d5ca69c 100644 --- a/construct_editor/gallery/test_bits_swapped_bitwise.py +++ b/construct_editor/gallery/test_bits_swapped_bitwise.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_bitwise.py b/construct_editor/gallery/test_bitwise.py index 04f6de5..d068fd5 100644 --- a/construct_editor/gallery/test_bitwise.py +++ b/construct_editor/gallery/test_bitwise.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_bytes_greedybytes.py b/construct_editor/gallery/test_bytes_greedybytes.py index cc39979..051d2df 100644 --- a/construct_editor/gallery/test_bytes_greedybytes.py +++ b/construct_editor/gallery/test_bytes_greedybytes.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_checksum.py b/construct_editor/gallery/test_checksum.py index 0facdd8..e3f8538 100644 --- a/construct_editor/gallery/test_checksum.py +++ b/construct_editor/gallery/test_checksum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import hashlib import construct as cs diff --git a/construct_editor/gallery/test_compressed.py b/construct_editor/gallery/test_compressed.py index 013803b..f621d9f 100644 --- a/construct_editor/gallery/test_compressed.py +++ b/construct_editor/gallery/test_compressed.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_computed.py b/construct_editor/gallery/test_computed.py index 4bf3f3a..f828675 100644 --- a/construct_editor/gallery/test_computed.py +++ b/construct_editor/gallery/test_computed.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_const.py b/construct_editor/gallery/test_const.py index 973c694..299cb76 100644 --- a/construct_editor/gallery/test_const.py +++ b/construct_editor/gallery/test_const.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_dataclass_bit_struct.py b/construct_editor/gallery/test_dataclass_bit_struct.py index 57d8436..93f12f7 100644 --- a/construct_editor/gallery/test_dataclass_bit_struct.py +++ b/construct_editor/gallery/test_dataclass_bit_struct.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_dataclass_struct.py b/construct_editor/gallery/test_dataclass_struct.py index b6d543b..f40a458 100644 --- a/construct_editor/gallery/test_dataclass_struct.py +++ b/construct_editor/gallery/test_dataclass_struct.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import typing as t diff --git a/construct_editor/gallery/test_default.py b/construct_editor/gallery/test_default.py index 34c7876..92453fc 100644 --- a/construct_editor/gallery/test_default.py +++ b/construct_editor/gallery/test_default.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_enum.py b/construct_editor/gallery/test_enum.py index 838a54c..b84e3ae 100644 --- a/construct_editor/gallery/test_enum.py +++ b/construct_editor/gallery/test_enum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_fixedsized.py b/construct_editor/gallery/test_fixedsized.py index cda2c7d..a514500 100644 --- a/construct_editor/gallery/test_fixedsized.py +++ b/construct_editor/gallery/test_fixedsized.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_flag.py b/construct_editor/gallery/test_flag.py index dff51a4..a27c7ed 100644 --- a/construct_editor/gallery/test_flag.py +++ b/construct_editor/gallery/test_flag.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_flagsenum.py b/construct_editor/gallery/test_flagsenum.py index 66dd5f0..6646471 100644 --- a/construct_editor/gallery/test_flagsenum.py +++ b/construct_editor/gallery/test_flagsenum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_focusedseq.py b/construct_editor/gallery/test_focusedseq.py index 8542c4f..7647a8f 100644 --- a/construct_editor/gallery/test_focusedseq.py +++ b/construct_editor/gallery/test_focusedseq.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_greedyrange.py b/construct_editor/gallery/test_greedyrange.py index 9075875..9bf756f 100644 --- a/construct_editor/gallery/test_greedyrange.py +++ b/construct_editor/gallery/test_greedyrange.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_ifthenelse.py b/construct_editor/gallery/test_ifthenelse.py index 92a24bf..3812ebb 100644 --- a/construct_editor/gallery/test_ifthenelse.py +++ b/construct_editor/gallery/test_ifthenelse.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_ifthenelse_nested_switch.py b/construct_editor/gallery/test_ifthenelse_nested_switch.py index 6d0503e..53c4926 100644 --- a/construct_editor/gallery/test_ifthenelse_nested_switch.py +++ b/construct_editor/gallery/test_ifthenelse_nested_switch.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_nullstripped.py b/construct_editor/gallery/test_nullstripped.py index e23d59f..b34c1df 100644 --- a/construct_editor/gallery/test_nullstripped.py +++ b/construct_editor/gallery/test_nullstripped.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_nullterminated.py b/construct_editor/gallery/test_nullterminated.py index 538cc82..f6670c5 100644 --- a/construct_editor/gallery/test_nullterminated.py +++ b/construct_editor/gallery/test_nullterminated.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_padded.py b/construct_editor/gallery/test_padded.py index 8119591..7cbb9fb 100644 --- a/construct_editor/gallery/test_padded.py +++ b/construct_editor/gallery/test_padded.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_padded_string.py b/construct_editor/gallery/test_padded_string.py index 4dcf022..537f869 100644 --- a/construct_editor/gallery/test_padded_string.py +++ b/construct_editor/gallery/test_padded_string.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_pass.py b/construct_editor/gallery/test_pass.py index 50fc8b1..33bf643 100644 --- a/construct_editor/gallery/test_pass.py +++ b/construct_editor/gallery/test_pass.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_pointer_peek_seek_tell.py b/construct_editor/gallery/test_pointer_peek_seek_tell.py index 9e9e751..77c1933 100644 --- a/construct_editor/gallery/test_pointer_peek_seek_tell.py +++ b/construct_editor/gallery/test_pointer_peek_seek_tell.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_renamed.py b/construct_editor/gallery/test_renamed.py index 093dbf7..559858b 100644 --- a/construct_editor/gallery/test_renamed.py +++ b/construct_editor/gallery/test_renamed.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_select.py b/construct_editor/gallery/test_select.py index e3bd76d..e5e0733 100644 --- a/construct_editor/gallery/test_select.py +++ b/construct_editor/gallery/test_select.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_select_complex.py b/construct_editor/gallery/test_select_complex.py index 1854f59..b185b9a 100644 --- a/construct_editor/gallery/test_select_complex.py +++ b/construct_editor/gallery/test_select_complex.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_stringencodded.py b/construct_editor/gallery/test_stringencodded.py index 885883c..ac1bd02 100644 --- a/construct_editor/gallery/test_stringencodded.py +++ b/construct_editor/gallery/test_stringencodded.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any, Dict import construct as cs diff --git a/construct_editor/gallery/test_switch.py b/construct_editor/gallery/test_switch.py index 91f4795..2ae91b8 100644 --- a/construct_editor/gallery/test_switch.py +++ b/construct_editor/gallery/test_switch.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct as cs from . import GalleryItem diff --git a/construct_editor/gallery/test_switch_dataclass.py b/construct_editor/gallery/test_switch_dataclass.py index 276bb9b..a976075 100644 --- a/construct_editor/gallery/test_switch_dataclass.py +++ b/construct_editor/gallery/test_switch_dataclass.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs @@ -19,7 +21,7 @@ class Case1(cst.DataclassMixin): case1_2: int = cst.csfield(cs.Int16sb) @classmethod - def get_default(cls) -> "SwitchTest.Case1": + def get_default(cls) -> SwitchTest.Case1: return cls(0, 0) @dataclasses.dataclass @@ -30,7 +32,7 @@ class Case2(cst.DataclassMixin): case2_4: int = cst.csfield(cs.Int8sb) @classmethod - def get_default(cls) -> "SwitchTest.Case2": + def get_default(cls) -> SwitchTest.Case2: return cls(0, 0, 0, 0) @dataclasses.dataclass @@ -38,7 +40,7 @@ class CaseDefault(cst.DataclassMixin): case_default_1: int = cst.csfield(cs.Int32sb) @classmethod - def get_default(cls) -> "SwitchTest.CaseDefault": + def get_default(cls) -> SwitchTest.CaseDefault: return cls(0) choice: int = cst.csfield(cst.TEnum(cs.Int8ub, Choice)) diff --git a/construct_editor/gallery/test_tenum.py b/construct_editor/gallery/test_tenum.py index 409c0c2..503811c 100644 --- a/construct_editor/gallery/test_tenum.py +++ b/construct_editor/gallery/test_tenum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_tflagsenum.py b/construct_editor/gallery/test_tflagsenum.py index 0b5a8de..4285522 100644 --- a/construct_editor/gallery/test_tflagsenum.py +++ b/construct_editor/gallery/test_tflagsenum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import construct as cs diff --git a/construct_editor/gallery/test_timestamp.py b/construct_editor/gallery/test_timestamp.py index ddfe33a..2783d72 100644 --- a/construct_editor/gallery/test_timestamp.py +++ b/construct_editor/gallery/test_timestamp.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import arrow diff --git a/construct_editor/main.py b/construct_editor/main.py index 4e21450..50dbcc1 100644 --- a/construct_editor/main.py +++ b/construct_editor/main.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys import typing as t from pathlib import Path diff --git a/construct_editor/wx_widgets/wx_construct_editor.py b/construct_editor/wx_widgets/wx_construct_editor.py index 8a5a80a..a11e9df 100644 --- a/construct_editor/wx_widgets/wx_construct_editor.py +++ b/construct_editor/wx_widgets/wx_construct_editor.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import annotations import dataclasses @@ -86,7 +85,7 @@ def GetMode(self) -> int: # we need to get the mode for this item. (Fingers crossed that # this always works.) - dvc: "dv.DataViewCtrl" = self.GetView() + dvc: dv.DataViewCtrl = self.GetView() editor = t.cast("WxConstructEditor", dvc.GetParent()) selected_entry = editor.get_selected_entry() if selected_entry is None: @@ -188,7 +187,7 @@ def entry_to_dvc_item(self, entry: EntryConstruct) -> dv.DataViewItem: # ################################################################################################################# # ConstructEditorModel Interface ################################################################################## # ################################################################################################################# - def on_value_changed(self, entry: "EntryConstruct"): + def on_value_changed(self, entry: EntryConstruct): dvc_item = self.entry_to_dvc_item(entry) self.ItemChanged(dvc_item) @@ -579,7 +578,7 @@ def _on_dvc_right_clicked(self, event: dv.DataViewEvent): Then a context menu is created """ item = event.GetItem() - entry: "EntryConstruct | None" + entry: EntryConstruct | None if item.ID is not None: entry = self._model.dvc_item_to_entry(item) else: diff --git a/construct_editor/wx_widgets/wx_construct_hex_editor.py b/construct_editor/wx_widgets/wx_construct_hex_editor.py index 1faa8cd..61bbf36 100644 --- a/construct_editor/wx_widgets/wx_construct_hex_editor.py +++ b/construct_editor/wx_widgets/wx_construct_hex_editor.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import annotations import typing as t @@ -52,7 +51,7 @@ def __init__( self.Initialize(panel) - self.sub_panel: "HexEditorPanel | None" = None + self.sub_panel: HexEditorPanel | None = None def clear_sub_panels(self): """Clears all sub-panels recursivly""" @@ -61,7 +60,7 @@ def clear_sub_panels(self): self.sub_panel.Destroy() self.sub_panel = None - def create_sub_panel(self, name: str, bitwise: bool) -> "HexEditorPanel": + def create_sub_panel(self, name: str, bitwise: bool) -> HexEditorPanel: """Create a new sub-panel""" if self.sub_panel is None: new_panel = HexEditorPanel(self, name, read_only=True, bitwiese=bitwise) diff --git a/construct_editor/wx_widgets/wx_context_menu.py b/construct_editor/wx_widgets/wx_context_menu.py index 2ef0515..92bf079 100644 --- a/construct_editor/wx_widgets/wx_context_menu.py +++ b/construct_editor/wx_widgets/wx_context_menu.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -import typing as t +from __future__ import annotations import wx @@ -31,9 +30,9 @@ class WxContextMenu(wx.Menu, ContextMenu): def __init__( self, - parent: "construct_editor.ConstructEditor", - model: "ConstructEditorModel", - entry: t.Optional["entries.EntryConstruct"], + parent: construct_editor.ConstructEditor, + model: ConstructEditorModel, + entry: entries.EntryConstruct | None, ): wx.Menu.__init__(self) ContextMenu.__init__(self, parent, model, entry) diff --git a/construct_editor/wx_widgets/wx_exception_dialog.py b/construct_editor/wx_widgets/wx_exception_dialog.py index 461d113..1588619 100644 --- a/construct_editor/wx_widgets/wx_exception_dialog.py +++ b/construct_editor/wx_widgets/wx_exception_dialog.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import traceback import typing as t diff --git a/construct_editor/wx_widgets/wx_hex_editor.py b/construct_editor/wx_widgets/wx_hex_editor.py index 873336e..27ef523 100644 --- a/construct_editor/wx_widgets/wx_hex_editor.py +++ b/construct_editor/wx_widgets/wx_hex_editor.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +from __future__ import annotations + import dataclasses import logging import math @@ -27,7 +28,7 @@ class HexEditorBinaryData: def __init__(self, binary: bytes) -> None: self._binary = bytearray(binary) - self.on_binary_changed: "CallbackList[[HexEditorBinaryData]]" = CallbackList() + self.on_binary_changed: CallbackList[[HexEditorBinaryData]] = CallbackList() self.command_processor = wx.CommandProcessor() def overwrite_all(self, byts: bytes): @@ -151,7 +152,7 @@ class HexEditorFormat: class HexEditorTable(Grid.GridTableBase): - def __init__(self, editor: "WxHexEditor", binary_data: HexEditorBinaryData): + def __init__(self, editor: WxHexEditor, binary_data: HexEditorBinaryData): super().__init__() self._editor = editor @@ -449,7 +450,7 @@ class HexCellEditor(Grid.GridCellEditor): wxPython demo. """ - def __init__(self, grid: "HexEditorGrid"): + def __init__(self, grid: HexEditorGrid): super().__init__() self.parentgrid = grid @@ -623,7 +624,7 @@ class HexEditorGrid(Grid.Grid): def __init__( self, - editor: "WxHexEditor", + editor: WxHexEditor, table: HexEditorTable, binary_data: HexEditorBinaryData, read_only: bool = False, @@ -633,7 +634,7 @@ def __init__( self._table = table self._binary_data = binary_data self.read_only = read_only - self.on_selection_changed: "CallbackList[[int, int | None]]" = ( + self.on_selection_changed: CallbackList[[int, int | None]] = ( CallbackList() ) @@ -1302,12 +1303,12 @@ def format(self, val: HexEditorFormat): # Property: on_binary_changed ############################################# @property - def on_binary_changed(self) -> "CallbackList[[HexEditorBinaryData]]": + def on_binary_changed(self) -> CallbackList[[HexEditorBinaryData]]: return self._binary_data.on_binary_changed # Property: on_binary_changed ############################################# @property - def on_selection_changed(self) -> "CallbackList[[int, int | None]]": + def on_selection_changed(self) -> CallbackList[[int, int | None]]: return self._grid.on_selection_changed diff --git a/construct_editor/wx_widgets/wx_obj_view.py b/construct_editor/wx_widgets/wx_obj_view.py index d8a283d..42da420 100644 --- a/construct_editor/wx_widgets/wx_obj_view.py +++ b/construct_editor/wx_widgets/wx_obj_view.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import typing as t import arrow @@ -145,7 +147,7 @@ class FlagsEnumComboPopup(wx.ComboPopup): def __init__( self, combo_ctrl: wx.ComboCtrl, - entry: t.Union["EntryTFlagsEnum", "EntryFlagsEnum"], + entry: EntryTFlagsEnum | EntryFlagsEnum, ): super().__init__() self.combo_ctrl = combo_ctrl @@ -194,7 +196,7 @@ def GetAdjustedSize(self, minWidth, prefHeight, maxHeight): prefHeight = min(row_height * row_count + 4, prefHeight) return wx.ComboPopup.GetAdjustedSize(self, minWidth, prefHeight, maxHeight) - def get_flagsenum_items(self) -> t.List["FlagsEnumItem"]: + def get_flagsenum_items(self) -> t.List[FlagsEnumItem]: # read all flagsenum items and modify checked status flagsenum_items: t.List[FlagsEnumItem] = [] for item in range(self.clbx.GetCount()): @@ -362,7 +364,7 @@ def __init__(self, settings: ObjViewSettings): def get_size( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, ) -> wx.Size: # Return the size needed to display the value. The renderer # has a helper function we can use for measuring text that is @@ -375,7 +377,7 @@ def get_size( def render( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, rect: wx.Rect, dc: wx.DC, state, @@ -392,7 +394,7 @@ def get_mode(self) -> int: def activate_cell( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, rect: wx.Rect, model: dv.DataViewModel, item: dv.DataViewItem, @@ -408,7 +410,7 @@ def __init__(self, settings: ObjViewSettings_Flag): def get_size( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, ) -> wx.Size: native_renderer: wx.RendererNative = wx.RendererNative.Get() win: wx.Window = renderer.GetView() @@ -418,7 +420,7 @@ def get_size( def render( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, rect: wx.Rect, dc: wx.DC, state, @@ -437,7 +439,7 @@ def get_mode(self) -> int: def activate_cell( self, - renderer: "wx_construct_editor.ObjectRenderer", + renderer: wx_construct_editor.ObjectRenderer, rect: wx.Rect, model: dv.DataViewModel, item: dv.DataViewItem, diff --git a/construct_editor/wx_widgets/wx_python_code_editor.py b/construct_editor/wx_widgets/wx_python_code_editor.py index 0b0b059..18d9083 100644 --- a/construct_editor/wx_widgets/wx_python_code_editor.py +++ b/construct_editor/wx_widgets/wx_python_code_editor.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +from __future__ import annotations import keyword import sys diff --git a/pyproject.toml b/pyproject.toml index 42e31fa..369f073 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -165,6 +165,7 @@ select = [ "F", "I", "UP007", + "UP037", "UP045", ]