MT004: HasRequiresPython

Overview

Property Value
ID MT004
Name HasRequiresPython
Group metadata
Severity ERROR

Description

Checks that the [project].requires-python field is defined in pyproject.toml.

Specifying the required Python version:

  • Prevents installation on incompatible versions
  • Helps pip resolve dependencies correctly
  • Communicates compatibility to users

What it checks

The check verifies that pyproject.toml contains:

[project]
requires-python = ">=3.11"

How to fix

Add the requires-python field to your pyproject.toml:

[project]
requires-python = ">=3.11"

Version specifiers

Specifier Meaning
>=3.11 Python 3.11 or later
>=3.10,<4 Python 3.10+ but not 4.x
>=3.9,<3.12 Python 3.9, 3.10, or 3.11
~=3.11 Compatible release (~= 3.11.0)

Choosing a minimum version

Consider:

  • Features used - What Python features does your code require?
  • Dependencies - What do your dependencies require?
  • User base - What versions do your users have?
  • Security - Older versions may lack security patches

Common choices (as of 2024):

Minimum Rationale
>=3.11 Latest features, good performance
>=3.10 Match patterns, union types
>=3.9 Broader compatibility

Configuration

Skip this check

[tool.pycmdcheck]
skip = ["MT004"]

CLI

pycmdcheck --skip MT004