Skip to content

Add type annotation for on_space parameter #605

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

Merged
merged 10 commits into from
Aug 4, 2025

Conversation

nkoskelo
Copy link

@nkoskelo nkoskelo commented Jul 7, 2025

When one asks for a dense representation of a modelmember via to_dense(on_space=?), there are 3 options that the on_space parameter accepts, Hilbert, HilbertSchmidt and minimal. However, when one is coding, editors will not populate these options unless there is a type annotation on the parameter on_space. This could lead to unintended behavior, if there is a misspelling for instance. The method to_sparse(on_space=?) also has this problem.

@nkoskelo nkoskelo requested review from pcwysoc, a team and rileyjmurray as code owners July 7, 2025 21:00
@nkoskelo nkoskelo requested review from adhumu, tjproct and coreyostrove and removed request for a team July 7, 2025 21:00
@nkoskelo nkoskelo changed the base branch from master to develop July 7, 2025 21:00
@nkoskelo nkoskelo marked this pull request as draft July 8, 2025 20:52
@nkoskelo nkoskelo changed the title Make space type an enum instead of arbitrary string for easier matching. Make space type a Literal instead of arbitrary string for easier matching. Jul 25, 2025
@nkoskelo nkoskelo marked this pull request as ready for review July 25, 2025 22:52
@coreyostrove coreyostrove added this to the 0.9.14 milestone Jul 26, 2025
@nkoskelo nkoskelo changed the title Make space type a Literal instead of arbitrary string for easier matching. Add type annotation for on_space parameter Aug 1, 2025
Copy link
Contributor

@rileyjmurray rileyjmurray left a comment

Choose a reason for hiding this comment

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

The current changes have __init__.py do a relative import, from .typing import SpaceT, from the new file pygsti/typing.py The fact that this is a relative import is easy to miss and led me to think that SpaceT was a built-in type of some kind. I'd prefer that __init__.py just define SpaceT directly, and that we remove pygsti/typing.py.

@nkoskelo, if you're strongly opposed to that approach, then let's change the name of pygsti/typing.py to pgsti/pgtypes.py or pygsti/pygtypes.

@rileyjmurray rileyjmurray merged commit a3ab2a6 into develop Aug 4, 2025
4 checks passed
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.

3 participants