Skip to content

fix(python): tolerate older virtualenv PythonSpec missing machine/free_threaded#3935

Open
SAY-5 wants to merge 2 commits intotox-dev:mainfrom
SAY-5:fix-old-virtualenv-missing-attrs
Open

fix(python): tolerate older virtualenv PythonSpec missing machine/free_threaded#3935
SAY-5 wants to merge 2 commits intotox-dev:mainfrom
SAY-5:fix-old-virtualenv-missing-attrs

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 10, 2026

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

Fixes #3934.

_validate_base_python iterates over ("implementation", "major", "minor", "micro", "architecture", "machine", "free_threaded") and unconditionally calls getattr(spec_name, key) on the PythonSpec returned by virtualenv. The machine and free_threaded attributes were introduced in newer virtualenv releases, so on systems that still ship an older virtualenv (e.g. OpenIndiana's system package, virtualenv 20.37.0), tox -e py314 aborts with:

AttributeError: 'PythonSpec' object has no attribute 'machine'

Switching the lookups to getattr(spec, key, None) makes the comparison safely treat the missing keys as "no constraint", restoring the pre-3815 behaviour for environments that have not upgraded virtualenv yet. Added a regression test that monkey-patches PythonSpec.from_string_spec to return an attribute-stripped spec.

…e_threaded

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Wouldn't this imply that on those environments we would not satisfy potentially the requirement? I would rather fail loud, like we do now, than silently do the wrong thing. People should upgrade their virtual lamp, and we should specifically require that, rather than this kind of fall back to bad behavior.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'PythonSpec' object has no attribute 'machine'

2 participants