Skip to content

Fix tomli compatibility issue for older Python version#286

Merged
Darktex merged 1 commit into
huggingface:mainfrom
AlirezaShamsoshoara:ali/bug_fix/_validation_tomli
Jan 12, 2026
Merged

Fix tomli compatibility issue for older Python version#286
Darktex merged 1 commit into
huggingface:mainfrom
AlirezaShamsoshoara:ali/bug_fix/_validation_tomli

Conversation

@AlirezaShamsoshoara

Copy link
Copy Markdown
Contributor

This PR addressing this issue: issue284

Summary

Fixes a ModuleNotFoundError when running OpenEnv CLI commands on Python 3.10 and older by adding a fallback import for the tomli package.

Problem

The tomllib module is only available in Python 3.11+. When running on Python 3.10 and older, the following error occurs:

$ openenv push
Traceback (most recent call last):
  ...
  File "/src/openenv/cli/_validation.py", line 15, in <module>
    import tomllib
ModuleNotFoundError: No module named 'tomllib'

Solution

Add a try/except import that falls back to tomli (the third-party backport) when tomllib is not available:

try:
    import tomllib
except ModuleNotFoundError:
    import tomli as tomllib

Changes

  • src/openenv/cli/_validation.py: Updated import to support Python 3.10 and older

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 12, 2026
@AlirezaShamsoshoara AlirezaShamsoshoara added the bug Something isn't working label Jan 12, 2026

@Darktex Darktex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

This PR fixes a ModuleNotFoundError when running OpenEnv CLI commands on Python 3.10 and older by adding a fallback import for the tomli package.

Overall Assessment: Simple, correct fix. Ready to merge.

Analysis

The fix is correct. tomllib was added to Python's standard library in Python 3.11, but the project's pyproject.toml specifies requires-python = ">=3.10". The tomli package is already listed as a dependency (tomli>=2.3.0), so this import fallback works correctly.

Aspect Assessment
Pattern used Standard Python compatibility pattern
Dependency already exists Yes (tomli>=2.3.0 in pyproject.toml)
API compatibility Yes (tomli has identical API to tomllib)

Note

PR #285 also includes this same fix (duplicated). Consider merging this PR first or letting it be included in PR #285.


Reviewed by Claude

@Darktex Darktex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Easy approval!

@Darktex Darktex merged commit 7d7ac21 into huggingface:main Jan 12, 2026
4 checks passed
@Darktex Darktex mentioned this pull request Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants