Skip to content

Switch type-checking from pyright to ty#242

Merged
stefanvanburen merged 3 commits intomainfrom
svanburen/ty
May 7, 2026
Merged

Switch type-checking from pyright to ty#242
stefanvanburen merged 3 commits intomainfrom
svanburen/ty

Conversation

@stefanvanburen
Copy link
Copy Markdown
Member

Figured I'd see how far along ty is; feels pretty good to me. Was able to eliminate more of the type checker ignores along the way.

Comment thread pyproject.toml Outdated
# Conformance test files import generated code as `from gen.connectrpc...` and
# sibling modules like `_util`/`_cov_embed`. Pytest and the launched server/client
# subprocesses put `conformance/test/` on sys.path; teach ty to do the same.
extra-paths = ["conformance/test"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this, plus dropping the __init__.py and reworking the imports above let us typecheck these.

Figured I'd see how far along `ty` is; feels pretty good to me. Was able
to eliminate more of the type checker ignores along the way.

Signed-off-by: Stefan VanBuren <svanburen@buf.build>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Copy link
Copy Markdown
Collaborator

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

One random side effect is using the default pyright version in VSCode for normal setups (not using ty language server which will continue to be the norm for a long time). Amazingly one patch version of drift (it loads 1.1.408) seems to cause this pyright bug in widening bytes to buffer protocol. Not our problem I would say but figured worth a share.

Image

Comment thread pyproject.toml
"tombi==0.10.2",
"ty==0.0.34",
"types-grpcio==1.0.0.20260408",
"types-protobuf==7.34.1.20260503",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks - didn't realize there was this hatch for getting protobuf working with it

Comment thread src/connectrpc/_server_async.py Outdated
)

if is_unary and isinstance(protocol, ConnectServerProtocol):
# Re-check via isinstance (rather than reusing `is_unary`) so the type
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I couldn't reproduce the issue - pushed a change to revert it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks, I thought I double-checked this; oh well!

import pytest

from ._util import VERSION_CONFORMANCE, coverage_env, maybe_patch_args_with_debug
from _util import VERSION_CONFORMANCE, coverage_env, maybe_patch_args_with_debug
Copy link
Copy Markdown
Collaborator

@anuraaga anuraaga May 7, 2026

Choose a reason for hiding this comment

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

I guess this doesn't hurt though adding conformance to the search paths would also make sense, I guess any pytest root should be added to it in principle.

Reminds me of the days when conformance was a separate pyproject, with renovate working properly we may consider eventually going back to that to reduce pythonpath worries

Comment thread src/connectrpc/_client_async.py Outdated
from asyncio import (
timeout as asyncio_timeout, # pyright: ignore[reportAttributeAccessIssue]
)
from asyncio import timeout as asyncio_timeout # ty: ignore[unresolved-import]
Copy link
Copy Markdown
Collaborator

@anuraaga anuraaga May 7, 2026

Choose a reason for hiding this comment

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

Using ImportError is a very old habit of mine for shims, but ever since version_info tuple I guess using that may be more idiomatic (typing-extensions uses it extensively), can consider rewriting to that to be properly type aware

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

switched in f3b7d18!

Allows us to drop the ty ignore.

Signed-off-by: Stefan VanBuren <svanburen@buf.build>
@stefanvanburen stefanvanburen marked this pull request as ready for review May 7, 2026 13:20
@stefanvanburen stefanvanburen merged commit b3c96a3 into main May 7, 2026
24 checks passed
@stefanvanburen stefanvanburen deleted the svanburen/ty branch May 7, 2026 13:35
stefanvanburen added a commit to bufbuild/protovalidate-python that referenced this pull request May 8, 2026
Redux of #418 - `ty` is still iterating, but now used over in
connect-python (connectrpc/connect-python#242); seems reasonable to be
consistent across our projects.
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