Modernize to Python 3.9: type hints with future annotations, exception handling, and code quality - #1189
Merged
Merged
Conversation
…e annotations, update type hints Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
|
Copilot
AI
changed the title
[WIP] Update codebase for Python 3.9 type hints and exceptions
Modernize to Python 3.9: type hints with future annotations, exception handling, and code quality
Jan 10, 2026
bact
marked this pull request as ready for review
January 10, 2026 22:42
2 tasks
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What does this changes
Modernizes codebase to Python 3.9 standards using
from __future__ import annotationsfor type hints, improves exception handling, and removes obsolete Python 2 artifacts.Type hints (191 files):
from __future__ import annotationsto enable PEP 604 syntax (X | None,X | Y) in Python 3.9List→list,Dict→dict,Optional[X]→X | None,Union[X, Y]→X | YLiteral,Protocol,TypeVar, etc.Code quality:
# -*- coding: utf-8 -*-headers (188 files) - obsolete in Python 3!= None→is not None(2 instances)ExceptionwithRuntimeErrorand added exception chaining (2 instances)corpus/__init__.pyandutil/__init__.pyConfiguration:
pyproject.tomlruff target topy39Example:
Before:
After:
What was wrong
Codebase used outdated Python 3.7-style type hints with explicit typing imports, retained Python 2 coding headers, and had generic exception handling without proper chaining.
How this fixes it
PEP 563's
from __future__ import annotationsstores type hints as strings, enabling PEP 604 pipe syntax in Python 3.9 without runtime evaluation. Automated with ruff UP rules, then manually fixed import order for circular dependency resolution.Your checklist for this pull request
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.