Skip to content

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

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

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.

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.

1 participant