Skip to content

Update typing aliases to use collections.abc instead#1677

Open
micpap25 wants to merge 12 commits into
quantumlib:mainfrom
micpap25:typings-update
Open

Update typing aliases to use collections.abc instead#1677
micpap25 wants to merge 12 commits into
quantumlib:mainfrom
micpap25:typings-update

Conversation

@micpap25
Copy link
Copy Markdown
Contributor

@micpap25 micpap25 commented Jul 16, 2025

Fixes #1653
following the recommendations described in the issue, replace all instances of deprecated aliases with the correct ones / built-ins.
This removes compatibility with pre-3.10 python versions, but Qualtran isn't intended to target those anymore.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@mhucka
Copy link
Copy Markdown
Contributor

mhucka commented May 17, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request performs a large-scale refactoring of type annotations across the codebase to align with modern Python standards (PEP 585). Specifically, it replaces deprecated typing module aliases like List, Dict, Tuple, Set, and Type with their built-in lowercase counterparts. Additionally, it migrates abstract collection types such as Iterable, Sequence, Callable, Iterator, and Mapping from typing to collections.abc. These changes are applied consistently across Python source files, development tools, and Jupyter notebooks, resulting in cleaner code and reduced reliance on the typing module. I have no feedback to provide.

Copy link
Copy Markdown
Contributor

@mhucka mhucka left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

This is a monster PR and it's hard to do individual line-oriented comments, so I'll have to summarize change requests and ask you to find the individual instances. Overall it looks good! There are just a few repeated patterns of changes that can be improved:

  • Some of the new Union types can be rewritten to simpler forms. There are two cases I see:

    • A type declaration of the form Union[X, None] can be rewritten as X | None, but it is safest to do this only if the X is not a quoted type name. For example, the case of

      call_graph_example: Union[BloqExample, None] = field()

      can be rewritten as

      call_graph_example: BloqExample | None = field()
    • Unions of the form Union[X, None] are also equivalent to Optional[X], and this is safer to use this variant if the X is a quoted type name. So for example,

      Union['cirq.Operation', None]

      can be converted to

      Optional['cirq.Operation']
  • Some combinations of Optional and Union can be further simplified. Here is an example:

    target_bitsizes: Optional[Union[SymbolicInt, tuple[SymbolicInt, ...]]] = None

    can be

    target_bitsizes: SymbolicInt | tuple[SymbolicInt, ...] | None = None
  • There are some remaining uses of typing.Type. I'm looking at qualtran/bloqs/data_loading/qroam_clean.py but are probably others. Basically, things like cls: Type['QROAMCleanAdjoint'] can be cls: type['QROAMCleanAdjoint'] and the import of Type from typing can be dropped.

That's all I have for now.

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.

replace deprecated typing aliases with those from collections

2 participants