Skip to content

[Python] [Typeguard] Part 6 - Add Typeguard SYNC Stack in tests#40353

Open
asheshvidyut wants to merge 269 commits intogrpc:masterfrom
asheshvidyut:feature/type-hints/typeguard-sync-stack-part-2
Open

[Python] [Typeguard] Part 6 - Add Typeguard SYNC Stack in tests#40353
asheshvidyut wants to merge 269 commits intogrpc:masterfrom
asheshvidyut:feature/type-hints/typeguard-sync-stack-part-2

Conversation

@asheshvidyut
Copy link
Member

@asheshvidyut asheshvidyut commented Jul 29, 2025

Description

Second Part of Add Typeguard to SYNC stack - runs only in tests, fixes type hints for SYNC Stack

This has changes from Part 5 #40278

Changes

TODO

Testing

CI

Related Work

Diff from Part - 5

diff --git a/bazel/_run_time_type_check_main.py b/bazel/_run_time_type_check_main.py
index 77c5d6dc23..b34707bfba 100644
--- a/bazel/_run_time_type_check_main.py
+++ b/bazel/_run_time_type_check_main.py
@@ -22,6 +22,12 @@ import unittest

from typeguard import install_import_hook

+# Fix the type hierarchy issue for HandlerCallDetails
+import grpc
+from grpc._cython import cygrpc
+# Register the cython class as a virtual subclass of the abstract base class
+grpc.HandlerCallDetails.register(cygrpc._HandlerCallDetails)
+
# AIO
install_import_hook('grpc.aio')
install_import_hook('grpc.aio._channel')
@@ -35,6 +41,7 @@ install_import_hook('grpc.aio._call')
install_import_hook('grpc.aio._metadata')

# SYNC
diff --git a/bazel/_run_time_type_check_main.py b/bazel/_run_time_type_check_main.py
index 77c5d6dc23..b34707bfba 100644
--- a/bazel/_run_time_type_check_main.py
+++ b/bazel/_run_time_type_check_main.py
@@ -22,6 +22,12 @@ import unittest

from typeguard import install_import_hook

+# Fix the type hierarchy issue for HandlerCallDetails
+import grpc
+from grpc._cython import cygrpc
+# Register the cython class as a virtual subclass of the abstract base class
+grpc.HandlerCallDetails.register(cygrpc._HandlerCallDetails)
+
# AIO
install_import_hook('grpc.aio')
install_import_hook('grpc.aio._channel')
@@ -35,6 +41,7 @@ install_import_hook('grpc.aio._call')
install_import_hook('grpc.aio._metadata')

# SYNC
+install_import_hook('grpc')
install_import_hook('grpc._auth')
install_import_hook('grpc._channel')
install_import_hook('grpc._common')
@@ -43,6 +50,10 @@ install_import_hook('grpc._interceptor')
install_import_hook('grpc._observability')
install_import_hook('grpc._plugin_wrapping')
install_import_hook('grpc._runtime_protos')
+install_import_hook('grpc._server')
+install_import_hook('grpc._simple_stubs')
+install_import_hook('grpc._typing')
+install_import_hook('grpc._utilities')

class SingleLoader:
    def __init__(
diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py
index 715514dba5..9fe34a6271 100644
--- a/src/python/grpcio/grpc/_server.py
+++ b/src/python/grpcio/grpc/_server.py
@@ -92,7 +92,7 @@ def _application_code(code: grpc.StatusCode) -> cygrpc.StatusCode:
    return cygrpc.StatusCode.unknown if cygrpc_code is None else cygrpc_code


-def _completion_code(state: _RPCState) -> cygrpc.StatusCode:
+def _completion_code(state: _RPCState) -> int:
    if state.code is None:
        return cygrpc.StatusCode.ok
    return _application_code(state.code)

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.

2 participants