Remove unnecessary quotes in type annotations - #44
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the codebase’s type annotations by enabling Ruff’s pyupgrade rule for unnecessary quoted annotations and then updating modules accordingly (primarily via from __future__ import annotations plus unquoted/PEP 604-style annotations).
Changes:
- Enable Ruff pyupgrade rule
UP037to flag and autofix unnecessary quoted annotations. - Add
from __future__ import annotationsbroadly to allow safe forward references without quotes. - Convert quoted/
typing.Union/Optionalstyle annotations to modernX | Y/T | Noneforms and unquote forward references.
Reviewed changes
Copilot reviewed 57 out of 57 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Enable Ruff UP037 to enforce removal of unnecessary quoted annotations. |
| construct_editor/wx_widgets/wx_python_code_editor.py | Add postponed evaluation for annotations to support unquoted forward refs. |
| construct_editor/wx_widgets/wx_obj_view.py | Replace quoted/Union[...] annotations with ` |
| construct_editor/wx_widgets/wx_hex_editor.py | Add postponed annotations and remove quoting in callback/type annotations. |
| construct_editor/wx_widgets/wx_exception_dialog.py | Add postponed annotations for consistency with de-quoted hints. |
| construct_editor/wx_widgets/wx_context_menu.py | Add postponed annotations and modernize constructor type hints. |
| construct_editor/wx_widgets/wx_construct_hex_editor.py | Remove quoted forward refs in return/attribute annotations using ` |
| construct_editor/wx_widgets/wx_construct_editor.py | Modernize a few annotations (e.g., remove quoted wx types). |
| construct_editor/main.py | Add postponed annotations support (module-wide consistency). |
| construct_editor/gallery/init.py | Add postponed annotations and unquote cs.Construct[...] annotation. |
| construct_editor/gallery/test_timestamp.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_tflagsenum.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_tenum.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_switch.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_switch_dataclass.py | Add postponed annotations and unquote nested-class return type refs. |
| construct_editor/gallery/test_stringencodded.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_select.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_select_complex.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_renamed.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_pointer_peek_seek_tell.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_pass.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_padded.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_padded_string.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_nullterminated.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_nullstripped.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_ifthenelse.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_ifthenelse_nested_switch.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_greedyrange.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_focusedseq.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_flagsenum.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_flag.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_fixedsized.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_enum.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_default.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_dataclass_struct.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_dataclass_bit_struct.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_const.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_computed.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_compressed.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_checksum.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_bytes_greedybytes.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_bitwise.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_bits_swapped_bitwise.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_array.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/test_aligned.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/example_pe32coff.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/gallery/example_ipstack.py | Add postponed annotations after module docstring (valid placement). |
| construct_editor/gallery/example_cmd_resp.py | Add postponed annotations to support unquoted annotations consistently. |
| construct_editor/core/preprocessor.py | Add postponed annotations and unquote/update typed hints (e.g., `GuiMetaData |
| construct_editor/core/model.py | Add postponed annotations and modernize `entries.EntryConstruct |
| construct_editor/core/entries.py | Add postponed annotations; convert many quoted refs to unquoted and modern union syntax. |
| construct_editor/core/custom.py | Add postponed annotations and modernize adapter/subconstruct type hints. |
| construct_editor/core/context_menu.py | Add postponed annotations and de-quote recursive MenuItem references. |
| construct_editor/core/construct_editor.py | Add postponed annotations and modernize callback ParamSpec usage. |
| construct_editor/core/commands.py | Add postponed annotations (module-wide consistency). |
| construct_editor/core/callbacks.py | Add postponed annotations; aligns with ParamSpec-based CallbackList typing usage. |
| construct_editor/core/init.py | Remove now-unnecessary encoding header comment (empty module). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import string | ||
| import typing as t | ||
| from typing import Any, Dict, List, Optional, Type | ||
| from typing import Any, Dict, List, Type |
There was a problem hiding this comment.
Would recommend switching to t.Any etc.
There was a problem hiding this comment.
And let's get rid of Dict and List in favor of dict and list.
| @@ -1,3 +1,5 @@ | |||
| from __future__ import annotations | |||
There was a problem hiding this comment.
Seems like you put this everywhere - even when not (yet) needed?
There was a problem hiding this comment.
Exactly. So we don't forget, in case we expand the file later. Only if that's there will Ruff recognize the “” quotes in the type hints as redundant and flag them as such.
No description provided.