-
-
Notifications
You must be signed in to change notification settings - Fork 199
Fix type annotations and improve code quality #967
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
base: master
Are you sure you want to change the base?
Conversation
…iles, and updates dependencies.
- Updated pytest version constraint to allow >=7.3.0 - All mark handling now uses pytest.Mark objects and iter_markers() - Added comprehensive audit script for mark compatibility verification - Updated documentation to reflect Pytest 7.3.0+ compatibility - Added mark registration in configuration files - All tests pass with Pytest 8.4.1 Fixes taverntesting#859 - Tavern marks broken with Pytest 7.3.0
… Update docs, changelog, requirements, and add audit script.
- Fix TypeSentinel type checking logic to properly handle type tokens - Use appropriate sample values for each constructor type (list, dict, etc.) - Ensure type tokens match actual values of correct type without requiring equality - Fix YAML loader to properly propagate BadSchemaError for empty values - All type token tests now pass (7/7) - All schema/loader tests now pass - Maintains backward compatibility while fixing edge cases
- Fix YAML constructor registration type issues in loader.py - Add proper type annotations to gRPC client functions - Fix MQTT client type annotation issues with mid parameter - Add comprehensive type hints to schema extensions - Fix pytest item type annotations and return types - Improve error handling with proper null checks - Add proper imports and function signatures - Fix entry.py function call issues - Improve Pylint score from 8.06/10 to 8.55/10 - All files now compile successfully and can be imported
- Documents 41.8% improvement in pylint score (6.34 to 8.99/10) - Details systematic improvements across 48 files - Includes quality metrics, test results, and recommendations - Signed by Douglas Mitchell, Senior Software Engineer
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 comprehensive PR addresses multiple type annotation issues and significantly improves code quality across the Tavern codebase, while fixing critical compatibility issues with Pytest 7.3.0+.
Key Changes:
- Fixed Pytest marks compatibility for Pytest 7.3.0+ by modernizing mark handling APIs
- Added comprehensive type hints and fixed type annotation issues across HTTP, MQTT, gRPC, and core modules
- Improved error handling with specific exception types and proper null checks
- Updated dependencies to support modern Pytest versions (7.3.0+)
Reviewed Changes
Copilot reviewed 83 out of 87 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/tavern_grpc/test_services_pb2_grpc.py | Updated gRPC service stubs with version compatibility checks and registered method handling |
| tests/unit/tavern_grpc/test_services_pb2.py | Modernized protobuf generated code with runtime version validation |
| tests/unit/tavern_grpc/test_grpc.py | Removed deprecated protobuf parameters for compatibility |
| tavern/_core/pytest/item.py | Fixed Pytest mark handling for 7.3.0+ compatibility with proper Mark objects |
| tavern/_core/pytest/file.py | Updated mark creation to use modern Pytest API |
| tavern/_core/loader.py | Enhanced YAML loading with better type safety and error handling |
| tavern/_plugins/mqtt/client.py | Added null checks for MQTT subscription handling |
| tavern/entry.py | Fixed function call signature for run_legacy |
| tavern/core.py | Refactored with dataclass configuration and improved type annotations |
| pyproject.toml | Updated Pytest dependency to support 7.3.0+ |
Comments suppressed due to low confidence (1)
tavern/_plugins/mqtt/client.py:1
- Good defensive programming with the null check for
mid. This prevents potential runtime errors when the MQTT library returns None for the message ID.
"""
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| preserving_proto_field_name=True, | ||
| ) | ||
|
|
||
| def body(self) -> Mapping: | ||
| return json_format.MessageToDict( | ||
| self.resp, | ||
| including_default_value_fields=True, | ||
| preserving_proto_field_name=True, |
Copilot
AI
Oct 8, 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.
The removal of including_default_value_fields=True parameter is correct for newer protobuf versions, but ensure this doesn't break existing tests that expect default values to be included in the output.
| try: | ||
| self._root = os.path.split(stream.name)[0] | ||
| # Fix attribute access issue - check if stream has name attribute | ||
| # Use getattr with default to avoid type checker issues | ||
| stream_name = getattr(stream, 'name', None) | ||
| if stream_name is not None: | ||
| self._root = os.path.split(stream_name)[0] | ||
| else: | ||
| self._root = os.path.curdir | ||
| except AttributeError: |
Copilot
AI
Oct 8, 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.
Good improvement using getattr with a default value instead of direct attribute access. This prevents AttributeError when the stream doesn't have a name attribute.
| @dataclass | ||
| class TavernConfig: | ||
| """Configuration object for Tavern test execution.""" | ||
|
|
||
| in_file: str | ||
| global_cfg: Union[dict, str, None] = None |
Copilot
AI
Oct 8, 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.
Excellent refactoring using dataclass for configuration. This improves type safety and makes the code more maintainable by clearly defining the expected configuration structure.
| "pyjwt>=2.5.0,<3", | ||
| "pykwalify>=1.8.0,<2", | ||
| "pytest>=7,<7.3", | ||
| "pytest>=7.3.0", |
Copilot
AI
Oct 8, 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.
Good update to support Pytest 7.3.0+. This aligns with the mark handling fixes throughout the codebase and removes the artificial version constraint.
| "pytest>=7.3.0", | |
| "pytest", |
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.
this file should not be here?
Summary
This PR addresses multiple type annotation issues and improves overall code quality across the Tavern codebase.
Key Changes
Type Annotation Fixes
Code Quality Improvements
Files Modified
Testing
Impact
This PR significantly improves code maintainability and type safety while preserving all existing functionality.