Skip to content

Add Literal type hints for IDE autocomplete - #1010

Closed
rafaelha wants to merge 5 commits into
quantumlib:mainfrom
rafaelha:main
Closed

rafaelha wants to merge 5 commits into
quantumlib:mainfrom
rafaelha:main

Conversation

@rafaelha

Copy link
Copy Markdown

Small quality of life improvement: Literal type hints to enable IDE autocomplete.

image

I tried to find all cases where Literal type hints can be provided. In a few places the stubs already had Literal type hints, but without importing from typing import Literal they did not do anything for me. I've gone ahead and added

try:
    from typing import Literal
except ImportError:
    pass

to dev/gen_stim_stub_file.py.

For Python <=3.7 one could also consider importing Literal from typing_extensions, but it's probably better not to introduce an additional dependency.

@Strilanc

Copy link
Copy Markdown
Collaborator

I was waiting for 3.6 and 3.7 support to be dropped before merging this (as I don't like the types being invalid in some of the versions). Now that that's happening, I've extended this change to not use the try-catch import in #1010 . Thanks for the submission!

@Strilanc Strilanc closed this Jan 13, 2026
@Strilanc Strilanc mentioned this pull request Jan 13, 2026
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