Skip to content

Convert more type annotations to latest Python built-in #7339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mhucka opened this issue May 14, 2025 · 8 comments
Open

Convert more type annotations to latest Python built-in #7339

mhucka opened this issue May 14, 2025 · 8 comments
Assignees
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/health For CI/testing/release process/refactoring/technical debt items kind/task A task that's part of a larger effort no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.

Comments

@mhucka
Copy link
Contributor

mhucka commented May 14, 2025

Recent versions of Python offer updated type annotation syntaxes. Cirq should make use of them.

@mhucka mhucka added the kind/task A task that's part of a larger effort label May 14, 2025
@pavoljuhas
Copy link
Collaborator

pavoljuhas commented May 14, 2025

Per PEP-585 we should use list[int] instead of typing.List[int] for type annotations. The ruff tool has an option to automate the fixup of old-style annotations - https://docs.astral.sh/ruff/rules/non-pep585-annotation/

We can also replace Union[str, int] with str | int and Optional[int] with int | None.
This can be checked with pylint rule consider-alternative-union-syntax

cc @codrut3

@pavoljuhas pavoljuhas added good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/health For CI/testing/release process/refactoring/technical debt items labels May 14, 2025
@Akshita07
Copy link
Contributor

Is anyone working on this? And is there already a related PR? If no one has already claimed it, I want to work on this task.

@codrut3
Copy link
Contributor

codrut3 commented May 16, 2025

Feel free to do this @Akshita07 Otherwise I'll have a look in a couple of days.

@Akshita07
Copy link
Contributor

Thank you @codrut3 :)

@mhucka
Copy link
Contributor Author

mhucka commented May 17, 2025

@Akshita07 OK, I've assigned it to you. Thank you for your interest!

With respect to this question: "is there already a related PR": there was not for this specific matter, but there is an ongoing series of PRs from @pavoljuhas to make some other type annotation updates. I don't think the changes will interfere with each other, but you may still want to take a look in the closed PRs for recent type annotation-related PRs by Pavol, and just look at what the changes involved.

@pavoljuhas
Copy link
Collaborator

Thanks @Akshita07 for your offer to help! I have an ongoing series of PRs to address #1999 which should be wrapped up by mid next week. It is probably better to hold on with your changes so there is no interference; that said, any files that were already touched in #7193, #7278, #7295, #7298, #7317, #7325, #7343 are safe to work on.

@Akshita07
Copy link
Contributor

Thanks @mhucka and @pavoljuhas for the information. I'll check the closed PRs and make my changes accordingly.

@pavoljuhas
Copy link
Collaborator

Hi @Akshita07, I am done with a possibly interfering PR #7357 and @dstrain115 with #7355.

Feel free to take this over to fix the remaining issues from

ruff check --target-version=py311 --select=UP006,UP007

github-merge-queue bot pushed a commit that referenced this issue May 21, 2025
Updates following type annotations:

- typing.Dict to dict
- typing.List to list
- typing.Tuple to tuple
- typing.Set to set
- typing.FrozenSet to frozenset
- typing.Type to type
- typing.Union to X | Y
- typing.Optional to X | None

Addresses issue [#7339]

---------

Co-authored-by: Pavol Juhas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/health For CI/testing/release process/refactoring/technical debt items kind/task A task that's part of a larger effort no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.
Projects
None yet
Development

No branches or pull requests

4 participants