Skip to content

Restore Python 3.11 support with conditional imports#15175

Merged
Carreau merged 1 commit intomainfrom
claude/restore-python-311-support-al5G3
Apr 3, 2026
Merged

Restore Python 3.11 support with conditional imports#15175
Carreau merged 1 commit intomainfrom
claude/restore-python-311-support-al5G3

Conversation

@Carreau
Copy link
Copy Markdown
Member

@Carreau Carreau commented Apr 2, 2026

Summary

This PR restores Python 3.11 support to IPython 9.x, reverting the previous deprecation. Python 3.11 continues to be supported thanks to funding from the D. E. Shaw group.

Key Changes

  • Minimum Python version: Updated from 3.12 to 3.11 across all configuration files (setup.py, pyproject.toml, IPython/init.py)
  • Conditional imports: Added version checks for typing features that differ between Python 3.11 and 3.12:
    • TypedDict and Protocol imported from typing_extensions on Python < 3.12
    • TypeAliasType imported from typing_extensions on Python < 3.12
  • System attribute handling: Added conditional logic for sys.last_exc which only exists in Python 3.12+
  • Tokenizer compatibility: Split SystemAssign.find() into find_pre_312() and find_post_312() methods to handle differences in Python's tokenizer between versions
  • Test coverage: Restored Python 3.11 to CI/CD matrix and added version-specific test conditions
  • Documentation: Updated whatsnew documentation to reflect Python 3.11 support restoration and added acknowledgment of D. E. Shaw group sponsorship
  • Dependencies: Added typing_extensions>=4.6 as a conditional dependency for Python < 3.12

Implementation Details

The changes maintain backward compatibility with Python 3.11 while preserving support for newer versions. Version checks are performed at import time where necessary, and runtime checks are used for features like sys.last_exc that may not exist in earlier versions. The tokenizer changes account for differences in how Python 3.11 and 3.12+ handle error tokens in system command assignments.

@Carreau Carreau force-pushed the claude/restore-python-311-support-al5G3 branch 2 times, most recently from cfaa38e to f13a15f Compare April 2, 2026 10:18
Reverts the Python 3.11 drop from PR #15121. This restores:

- requires-python >= 3.11 in pyproject.toml
- typing_extensions conditional dependency for Python < 3.12
- Conditional imports for TypedDict, Protocol, TypeAliasType from
  typing_extensions on Python < 3.12
- The find_pre_312 tokenizer path in inputtransformer2.py for
  system assignments (a = !foo) where ! is ERRORTOKEN on 3.11
- Version-gated sys.last_exc usage (added in Python 3.12)
- Python 3.11 in CI test matrix and oldest-deps job
- Version check in setup.py and IPython/__init__.py
- Enum autoreload test for Python < 3.12

Add tip about D.E. Shaw funding Python 3.11 support

On Python < 3.12, include a random tip noting that IPython support
for Python versions outside of SPEC-0 is funded by D.E. Shaw.

Partial revert of #15121
@Carreau Carreau force-pushed the claude/restore-python-311-support-al5G3 branch from 2e2c089 to acad273 Compare April 3, 2026 12:46
@Carreau Carreau added this to the 9.13 milestone Apr 3, 2026
@Carreau Carreau merged commit f96610c into main Apr 3, 2026
25 checks passed
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