Skip to content

Use PEP604 syntax (X | Y / X | None)#42

Merged
timrid merged 1 commit into
mainfrom
remove-typing-optional
Jul 20, 2026
Merged

Use PEP604 syntax (X | Y / X | None)#42
timrid merged 1 commit into
mainfrom
remove-typing-optional

Conversation

@timrid

@timrid timrid commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Use PEP604 union syntax "X | Y" instead of "Union[X, Y]" and "X | None" instead of "Optional[X]" in type hints. We are using Python 3.10+ so we can use the new syntax.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes type hints across the project by switching from typing.Union[...] / typing.Optional[...] to PEP 604 union syntax (X | Y, X | None), aligning the codebase with the stated Python 3.10+ requirement.

Changes:

  • Replace t.Union[...] / t.Optional[...] annotations with PEP 604 (|) syntax in runtime code, tests, and stub files.
  • Enable Ruff pyupgrade rules (UP007, UP045) to enforce the new union style going forward.
  • Document the change in CHANGELOG.md.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_typed.py Updates dataclass field annotations to `X
tests/test_typed_pyright.py Updates optional bytes annotations to `bytes
tests/declarativeunittest.py Converts several helper aliases and overload signatures to PEP 604 unions.
pyproject.toml Enables Ruff UP007/UP045 to enforce PEP 604 union/optional style.
construct-stubs/lib/py3compat.pyi Updates union types in stubs to PEP 604 syntax.
construct-stubs/lib/containers.pyi Updates stub union types to PEP 604 syntax.
construct-stubs/lib/bitstream.pyi Updates optional/union stub types to PEP 604 syntax.
construct-stubs/expr.pyi Updates union/optional stub types to PEP 604 syntax.
construct-stubs/debug.pyi Updates optional callable type to PEP 604 syntax.
construct-stubs/core.pyi Broad conversion of unions/optionals in core stubs to PEP 604 syntax.
construct_typed/tenum.py Updates optional/union annotations in enum helpers to PEP 604 syntax.
construct_typed/generic_wrapper.py Updates a type alias to PEP 604 syntax.
construct_typed/dataclass_struct.py Updates several function parameter annotations to PEP 604 syntax.
CHANGELOG.md Notes the migration to PEP 604 type hint syntax.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyproject.toml
…e" instead of "Optional[X]" in type hints. We are using Python 3.10+ so we can use the new syntax.
@timrid
timrid force-pushed the remove-typing-optional branch from 9873f41 to 270d277 Compare July 20, 2026 10:54
@timrid
timrid merged commit f7f1ed4 into main Jul 20, 2026
22 checks passed
@timrid
timrid deleted the remove-typing-optional branch July 20, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants