Created
July 29, 2025 12:38
-
-
Save apoorvparijat/193b287789d52a92f5ca70fd535172a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typeguard import install_import_hook, TypeguardFinder, config | |
| # COPY-PASTE SOLUTION: Custom TypeguardFinder with Debug Configuration | |
| # Step 1: Configure debug instrumentation | |
| config.debug_instrumentation = True # Set to False to disable debug | |
| # Step 2: Define packages to instrument | |
| packages_to_instrument = [ | |
| 'grpc.aio', | |
| 'grpc.aio._channel', | |
| 'grpc.aio._server', | |
| 'grpc.aio._utils', | |
| 'grpc.aio._interceptor', | |
| 'grpc.aio._base_channel', | |
| 'grpc.aio._base_server', | |
| 'grpc.aio._typing', | |
| 'grpc.aio._call', | |
| 'grpc.aio._metadata', | |
| # SYNC - Test only grpc._server to confirm it's causing the HandlerCallDetails TypeCheckError | |
| 'grpc._server', | |
| ] | |
| # Step 3: Create custom TypeguardFinder (optional - customize as needed) | |
| class CustomTypeGuardFinder(TypeguardFinder): | |
| def should_instrument(self, module_name: str) -> bool: | |
| # Custom logic here if needed, or just use parent implementation | |
| result = super().should_instrument(module_name) | |
| if config.debug_instrumentation and result: | |
| print(f"DEBUG: Instrumenting module: {module_name}") | |
| return result | |
| # Step 4: Install import hook with custom finder | |
| install_import_hook(packages_to_instrument, cls=CustomTypeGuardFinder) |
Author
apoorvparijat
commented
Jul 29, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment