Skip to content

fix: support Python 3.11 by replacing PEP 695 type aliases with TypeAlias#4

Closed
zhiyichin wants to merge 1 commit into
matomatical:mainfrom
zhiyichin:fix/python311-type-alias-syntax
Closed

fix: support Python 3.11 by replacing PEP 695 type aliases with TypeAlias#4
zhiyichin wants to merge 1 commit into
matomatical:mainfrom
zhiyichin:fix/python311-type-alias-syntax

Conversation

@zhiyichin

Copy link
Copy Markdown

Motivation

matthewplotlib currently uses Python 3.12+ type X = Y syntax (PEP 695 type aliases) in three files: colormaps.py, colors.py, and data.py. This causes a SyntaxError on Python 3.11 and earlier, making the package unusable in those environments:

File ".../matthewplotlib/colormaps.py", line 25
    type ContinuousColorMap = Callable[
         ^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax

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

  • Replace type X = Y aliases in colormaps.py, colors.py, and data.py with typing.TypeAlias, which is available
    under the project’s existing Python >=3.10 requirement.
  • Union types written as A | B | C in the alias bodies are rewritten as Union[A, B, C] for the same reason.
  • No functional or runtime behavior changes, types are annotations only.

Checklist

  • No new dependencies beyond typing_extensions, which is already a transitive dependency of most scientific Python stacks and is explicitly required by many packages already.

@matomatical matomatical self-assigned this Jun 23, 2026
@matomatical

Copy link
Copy Markdown
Owner

New dependency typing_extensions should be listed in pyproject.toml (even if it happens to be a transitive dependency).

@matomatical

Copy link
Copy Markdown
Owner

Thank you for the PR. The issue you raise about matthewplotlib failing to support Python 3.11 is real. However, since I like the new typing features in 3.12+ and Python 3.11 is getting old, I've decided to drop official support for Python <=3.11 instead of incorporating your fix. As of matthewplotlib 0.4.0, we require Python >=3.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants