Skip to content

Adding ty type checking (experimental) - #1371

Draft
cdbf1 wants to merge 19 commits into
mainfrom
feature/ty_type_checking
Draft

Adding ty type checking (experimental)#1371
cdbf1 wants to merge 19 commits into
mainfrom
feature/ty_type_checking

Conversation

@cdbf1

@cdbf1 cdbf1 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@vtomole

vtomole commented Apr 8, 2026

Copy link
Copy Markdown
Member

Sounds like we should introduce this gradually, so we can have it run on modules that pass for first pass and then be able to merge.

@vtomole

vtomole commented Apr 15, 2026

Copy link
Copy Markdown
Member

To get this to pass, install something like types-requests.

@cdbf1
cdbf1 requested a review from richrines1 April 16, 2026 07:47
Comment thread general-superstaq/general_superstaq/machine_api.py Outdated
Comment thread general-superstaq/general_superstaq/models.py Outdated
Comment on lines +308 to +312
error_content = {str(key): value for key, value in json_content.items()}
detail = error_content.get("detail")
alternative = detail if isinstance(detail, str) else ""
message_content = error_content.get("message")
message = message_content if isinstance(message_content, str) else alternative

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we change the annotation of _handle_response to pydantic.JsonValue (which is more precise anyway) we can revert these changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree with updating annotation of _handle_response to pydantic.JsonValue and while this satisfies ty it introduces an error from mypy instead (since json_content.get("detail", "") is not garunteed to be a string.
Ultimately, either way some handling of non-string response values is required.

I've modified a little bit to now satisfy both

return credentials

@staticmethod
def _normalize_job_ids(job_ids: Sequence[str] | Sequence[uuid.UUID]) -> list[uuid.UUID]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pydantic is supposed to do this kind of type coercion for us, i don't think we should be adding these manual validations/conversions on top of it (for example the pydantic plugin for mypy tells it to treat model arguments as Any by default, but unfortunately it seems like ty's pydantic support is still a wip..)

not sure how to best circumvent this though.. one possible (but definitely suboptimal) workaround would be to add something like

[tool.ty.analysis]
replace-imports-with-any = ["pydantic.main.**"]

to our pyproject.yaml?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pydantic does the coercion for us, but ty is correct that we are technically passing in a value of the wrong type since pydantic doesnt have a way of annotating the coercion it does. For now my suggestion is targeted ignore lines.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm now i'm a little confused. shouldn't the type checker only care about the annotation of __init__ when checking the arguments passed to the class constructor? pydantic.BaseModel.__init__ has this annotation:

def __init__(self, /, **data: Any) -> None:

which should mean that all input arguments accept anything

@cdbf1
cdbf1 requested a review from richrines1 April 21, 2026 13:14
Comment thread .github/workflows/ci.yml
Comment on lines 73 to 119
@@ -93,6 +93,27 @@ jobs:
run: |
checks/mypy_.py

ty:
name: Type check (ty)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python 3.14
uses: actions/setup-python@v6
with:
python-version: 3.14
- uses: actions/cache@v5
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('**/pyproject.toml', '**/*requirements.txt', '.github/workflows/ci.yml') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ./checks-superstaq -e ./general-superstaq[dev] -e ./qiskit-superstaq[dev] -e ./cirq-superstaq[dev] -e ./supermarq-benchmarks[dev]
- name: Type check
run: |
checks/ty_.py general-superstaq

coverage:
name: Pytest and Coverage check
strategy:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we set a minimum supported Python version for client? We say 3.9 in the docs. Or, is the goal to bring all type-syntax up to date with 3.14?

@bharat-thotakura bharat-thotakura May 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Relevant: ty docs on inferring the Python version.

We may want to check explicitly setting this (like you can in mypy)

parser.description = textwrap.dedent(
"""
Runs ty on the repository (typing check).
Ignores files in the [repo_root]/examples directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this handled somewhere? Or are we ignoring it for now since gss has no examples?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, that was because I copied it from somewhere else - thanks for catching!

@dowusu-antwi

dowusu-antwi commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Dev discussion: Consider doing some kind of ty ignore (not sure about syntax) for the expected type errors, b/c ty is still in alpha and so this might change.

@dowusu-antwi

Copy link
Copy Markdown
Contributor

@cdbf1

cdbf1 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Oh yeah, pyrefly looks interesting. I read a useful comparison blog which highlights some of the differences in approach nicely: https://blog.edward-li.com/tech/comparing-pyrefly-vs-ty/

bharat-thotakura added a commit that referenced this pull request Aug 12, 2026
Factors out the addition of `checks-superstaq/checks_superstaq/ty_.py`
from #1371 for independent use. Closes
#1437

(also includes a tangential type check fix with
59c42b7)

---------

Signed-off-by: Bharath <bharath.thotakura@infleqtion.com>
@richrines1
richrines1 marked this pull request as draft September 2, 2026 15:43
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.

5 participants