Skip to content

Conversation

@EwoutH
Copy link
Member

@EwoutH EwoutH commented Oct 7, 2025

This PR updates Mesa to require Python 3.12 as the minimum version and adopts the new PEP 695 type parameter syntax introduced in Python 3.12.

Python 3.11 support is dropped following SPEC 0. The Mesa 3.3.x release series will keep supporting Python 3.11.

Key changes:

  • Updated minimum Python version from 3.11 to 3.12 across pyproject.toml, documentation, and pre-commit configuration
  • Replaced legacy Generic[T] + TypeVar syntax with modern type parameter syntax (class MyClass[T: Bound]:)
  • Removed redundant Generic inheritance where classes already inherit from generic base classes
  • Applied the new syntax to DiscreteSpace, CellCollection, Grid, and decorator type hints

Please review. I would like to fast-forward merge this myself.

EwoutH added 4 commits October 7, 2025 20:40
This commit drops Python 3.11 support and require Python 3.12+ following SPEC 0.

See the Python 3.12 release notes: https://docs.python.org/3/whatsnew/3.12.html

The Mesa 3.3.x release series will keep supporting Python 3.11.
With the minimum Python version now at 3.12, we can use the modern type parameter syntax (PEP 695) instead of the legacy Generic[T] pattern. This change improves code readability and aligns with current Python typing best practices.

Changes:
- CellCollection: Convert from Generic[T] to type parameter syntax with Cell bound
- DiscreteSpace: Convert from Generic[T] to type parameter syntax with Cell bound
- Grid: Remove redundant Generic[T] inheritance (already inherits from DiscreteSpace[T])
- accept_tuple_argument: Convert function type variable to use type parameter syntax
- Remove unused Generic imports from typing module

These changes are purely syntactic modernizations with no functional impact. The type parameter syntax is more concise and better integrated with Python's type system.

Fixes ruff UP046 and UP047 violations.
The Grid class inherits from DiscreteSpace[T], which already provides generic type support. The additional Generic[T] inheritance is redundant and triggers a ruff UP046 violation.

Changes:
- Remove Generic[T] from Grid class inheritance
- Remove unused Generic import from typing module
- Keep TypeVar T definition as it's still needed for DiscreteSpace[T] parameterization

Fixes ruff UP046 violation in grid.py.
@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.3% [-2.9%, -1.6%] 🔵 -0.0% [-0.2%, +0.2%]
BoltzmannWealth large 🔵 -2.2% [-2.6%, -1.7%] 🟢 -4.9% [-6.1%, -3.7%]
Schelling small 🔵 -0.6% [-1.1%, -0.0%] 🔵 -0.1% [-0.3%, +0.1%]
Schelling large 🔵 -1.6% [-2.3%, -1.0%] 🔵 -1.9% [-3.0%, -0.9%]
WolfSheep small 🔵 -0.3% [-0.5%, -0.1%] 🔵 -0.7% [-0.8%, -0.5%]
WolfSheep large 🔵 -0.3% [-0.4%, -0.1%] 🔵 -2.1% [-3.2%, -1.3%]
BoidFlockers small 🔵 +1.0% [+0.6%, +1.5%] 🔵 +0.8% [+0.6%, +0.9%]
BoidFlockers large 🔵 +0.0% [-0.3%, +0.4%] 🔵 +0.3% [+0.1%, +0.4%]

@EwoutH EwoutH requested review from quaquel and tpike3 October 7, 2025 19:18
Copy link
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

@EwoutH EwoutH merged commit e21a5b5 into projectmesa:main Oct 8, 2025
11 checks passed
@EwoutH EwoutH added the maintenance Release notes label label Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants