fix: support Python 3.11 by replacing PEP 695 type aliases with TypeAlias#4
Open
zhiyichin wants to merge 1 commit into
Open
fix: support Python 3.11 by replacing PEP 695 type aliases with TypeAlias#4zhiyichin wants to merge 1 commit into
zhiyichin wants to merge 1 commit into
Conversation
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.
Motivation
matthewplotlibcurrently uses Python 3.12+type X = Ysyntax (PEP 695 type aliases) in three files:colormaps.py,colors.py, anddata.py. This causes a SyntaxError on Python 3.11 and earlier, making the package unusable in those environments:The project currently declares
requires-python = ">=3.10"and lists Python 3.10 and 3.11 in its classifiers, so the package should remain importable on those versions. There is no functional reason to require Python 3.12 for aliases that are only used as type annotations.Modifications
type X = Yaliases incolormaps.py,colors.py, anddata.pywithtyping.TypeAlias, which is availableunder the project’s existing Python >=3.10 requirement.
A | B | Cin the alias bodies are rewritten asUnion[A, B, C]for the same reason.Checklist
typing_extensions, which is already a transitive dependency of most scientific Python stacks and is explicitly required by many packages already.