Skip to content

[Python] Typehints in Sync Stack#41210

Draft
asheshvidyut wants to merge 617 commits into
grpc:masterfrom
asheshvidyut:typehints-sync-stack
Draft

[Python] Typehints in Sync Stack#41210
asheshvidyut wants to merge 617 commits into
grpc:masterfrom
asheshvidyut:typehints-sync-stack

Conversation

@asheshvidyut

@asheshvidyut asheshvidyut commented Dec 9, 2025

Copy link
Copy Markdown
Member

@asheshvidyut asheshvidyut added the release notes: yes Indicates if PR needs to be in release notes label Dec 9, 2025
@asheshvidyut asheshvidyut changed the title [WIP] Typehints in Sync Stack [Python] Typehints in Sync Stack Dec 9, 2025
Comment thread src/python/grpcio/grpc/typing.py Outdated
"""Type alias for cygrpc.BaseEvent."""

else:
CygrpcChannelCredentials = cygrpc.ChannelCredentials

@sergiitk sergiitk Dec 18, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think they meant something like this in https://github.com/grpc/grpc/pull/37967/changes#r1853124380

class CygrpcChannelCredentials:
  _cy_creds: cygrpc.ChannelCredentials

  # private
  def __init__(self, cy_creds: cygrpc.ChannelCredentials):
      self._cy_creds = cy_creds

  # if there's a property or method we want to expose publically
  # let's pretend we need to expose some_bytes from cygrpc.ChannelCredentials
  @property
  def some_bytes(self) -> bytes:
    return bytes(self._cy_creds.some_bytes)

murgatroid99 and others added 19 commits March 28, 2026 07:18
These jobs have recently been failing with timeout errors, and the opt build recently passed once and completed just under the time limit. That implies that the run time is close to the current limit, and increasing the limit should significantly increase the success rate.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes grpc#41941

COPYBARA_INTEGRATE_REVIEW=grpc#41941 from murgatroid99:kokoro_windows_bazel_timeout 6242a54
PiperOrigin-RevId: 890030850
Similar to grpc#41941, this test job has frequently been failing with timeout errors, and when it passes, it gets close to the timeout. So, increasing the timeout should make it pass more consistently.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes grpc#41942

COPYBARA_INTEGRATE_REVIEW=grpc#41942 from murgatroid99:kokoro_macos_bazel_timeout 0e8d975
PiperOrigin-RevId: 890494537
Closes grpc#41901

COPYBARA_INTEGRATE_REVIEW=grpc#41901 from markdroth:error_flatten_expiry_update 10c8bde
PiperOrigin-RevId: 890644401
… stack (grpc#41940)

It looks like this bug was introduced back in grpc#38874 when I originally implemented the error_flatten changes.  I'm honestly surprised that nothing has caught this until now.

Closes grpc#41940

COPYBARA_INTEGRATE_REVIEW=grpc#41940 from markdroth:error_flatten_v3_fix adaa7b0
PiperOrigin-RevId: 890647719
In the original subchannel code, we reset backoff when a successful connection fails, which is fine, because we can't possibly be using the backoff state until we try to start the next connection attempt, and we aren't going to do that while we still have a working connection.

When I forked the subchannel code to implement connection scaling, I kept the backoff reset in the same place, but that is no longer the right place to do it: we can now start a new connection attempt before the working connection fails.  So this PR fixes the new subchannel implementation to instead reset the backoff when the connection attempt succeeds.

Closes grpc#41906

COPYBARA_INTEGRATE_REVIEW=grpc#41906 from markdroth:subchannel_backoff_fix 921b964
PiperOrigin-RevId: 890650249
…nce (grpc#41945)

Minor fix and improvement.

1. Fixes `SyntaxWarning: invalid escape sequence` for '\+' and '\.'
2. Removes unnecessary `\-` escapes
3. Optimization: pre-compile regex

Closes grpc#41945

COPYBARA_INTEGRATE_REVIEW=grpc#41945 from sergiitk:fix/ci/filter-pull-requests/regex-warnings 4042060
PiperOrigin-RevId: 890652175
Implements gRFC A103 (grpc/proposal#511).

Note: This does not yet include the CEL matching support, which will be implemented separately.

The filter is implemented as a v3 interceptor.  In order to run this in the v1 stack, I have introduced a new adaptor called `V3InterceptorToV2Bridge` that allows running a v3 interceptor as a v2 filter, which will then sit on top of the PromiseBasedFilter code to run on the v1 stack.

Currently, we do not have a unit test framework for v3 interceptors, so the only tests here are end2end tests.  Once we have such a framework, we can write unit tests as well.

Closes grpc#41196

PiperOrigin-RevId: 890708861
try using reduce_ex and IntEnum for TypeGuard Part 6 PR

@sreenithi sreenithi left a comment

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.

Haven't reviewed it fully yet. Just caught these on first glance, will do a more thorough review later.

Comment on lines +439 to +449
def is_active(self) -> bool:
"""See grpc.RpcContext.is_active."""
return False

def time_remaining(self) -> Optional[float]:
"""See grpc.RpcContext.time_remaining."""
return None

def add_callback(self, callback: NullaryCallbackType) -> bool:
"""See grpc.RpcContext.add_callback."""
return False

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.

why are these new methods being added?

rpc_event,
state,
send_response,
cast("Iterator[Any]", response_iterator),

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.

here are elsewhere throughout the PR, using cast to force the type on the type checker doesn't seem like the right thing to do. Please see if it can be resolved in any other way and use this only as the last resort if there is nothing else feasible to do.

cpu_cost: 1000
- script: tools/distrib/pylint_code.sh
- script: tools/distrib/ruff_code.sh
- script: tools/distrib/pyright_code.sh

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.

also add this to tools/distrib/sanitize.sh so that people can run it locally too.

@asheshvidyut asheshvidyut marked this pull request as draft April 27, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.