-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Run type check as first step #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
TypeError: cannot inherit from both a TypedDict type and a non-TypedDict base class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces mypy type checking as a CI/CD step and addresses various type-related issues throughout the codebase. The changes refactor duplicated type definitions into a shared generic base type, add type ignore comments where dynamic attribute assignment occurs, and rename exception variables for clarity.
Key changes:
- Adds mypy type checking workflow and Makefile target
- Introduces generic
TranscribeOutputBase[SegmentT]to eliminate duplicate type definitions - Adds type ignore comments for dynamic attribute assignments and runtime monkey-patching
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/typecheck.yml |
New GitHub Actions workflow to run type checking on push/PR to master |
Makefile |
Adds typecheck target with mypy configuration |
setup.cfg |
Adds mypy and types-requests to dev dependencies |
speech_recognition/recognizers/whisper_local/base.py |
Introduces generic TranscribeOutputBase and updates Protocol with generics |
speech_recognition/recognizers/whisper_local/whisper.py |
Removes duplicate TranscribeOutput definition, uses shared TranscribeOutputBase |
speech_recognition/recognizers/whisper_local/faster_whisper.py |
Removes duplicate TranscribeOutput definition, uses shared TranscribeOutputBase |
speech_recognition/recognizers/google_cloud.py |
Changes encoding type from enum to int for type compatibility |
speech_recognition/__init__.py |
Adds type ignore comments for dynamic attributes and renames exception variables |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class TranscribeOutputBase(TypedDict, Generic[SegmentT]): | ||
| text: str | ||
| segments: list[SegmentT] | ||
| language: str |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypedDict does not support inheritance from Generic in Python. While this syntax may work in some type checkers, it's not officially supported and could lead to runtime errors or inconsistent behavior across different type checkers. Consider using a Protocol with properties instead, or use a regular class with dataclass for better type safety.
| """ | ||
|
|
||
| encoding: Required[RecognitionConfig.AudioEncoding] | ||
| encoding: Required[int] |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the type from RecognitionConfig.AudioEncoding to int reduces type safety. While RecognitionConfig.AudioEncoding values are integers, using the specific enum type provides better type checking and makes the API clearer. If this change is necessary for type checking to pass, consider using RecognitionConfig.AudioEncoding | int or investigate why mypy is having issues with the original type.
| encoding: Required[int] | |
| encoding: Required["RecognitionConfig.AudioEncoding | int"] |
Code Review by Claude Sonnet 4.5 (
|
Inspired by #859