Skip to content
Python

fix: import tomllib's tomli fallback on Python 3.10

coderdailyoneabb7eef86351
diff --git a/coworker/config.py b/coworker/config.py
index 336d4af8..a25a7c2a 100644
--- a/coworker/config.py
+++ b/coworker/config.py
@@ -9,7 +9,10 @@ workspace path. Other permission grants remain global-only.
from __future__ import annotations
-import tomllib
+try:
+ import tomllib # stdlib since 3.11
+except ModuleNotFoundError: # 3.10, the floor requires-python declares
+ import tomli as tomllib # type: ignore[no-redef]
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Optional
diff --git a/pyproject.toml b/pyproject.toml
index 687dad70..3c1f10f4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -34,6 +34,8 @@ dependencies = [
# IANA tz database for zoneinfo. Windows ships no system tz db, so without this every
# named schedule timezone (UTC, Asia/Kolkata, …) silently falls back to local time.
"tzdata; sys_platform == 'win32'",
+ # tomllib landed in the 3.11 stdlib; on the 3.10 floor config.py falls back to tomli.
+ "tomli>=2; python_version < '3.11'",
]
[project.optional-dependencies]