Skip to content

Commit a4846aa

Browse files
committed
Fix tomllib.
1 parent b42b3c6 commit a4846aa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/_pytask/config_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
from __future__ import annotations
33

44
import os
5+
import sys
56
from pathlib import Path
67
from typing import Any
78

89
import click
9-
import tomli
1010
from _pytask.shared import parse_paths
1111

12+
if sys.version_info >= (3, 11):
13+
import tomllib
14+
else:
15+
import tomli as tomllib
16+
1217

1318
def set_defaults_from_config(
1419
context: click.Context, param: click.Parameter, value: Any # noqa: ARG001
@@ -85,7 +90,7 @@ def _find_project_root_and_config(paths: list[Path] | None) -> tuple[Path, Path
8590
if path.exists():
8691
try:
8792
read_config(path)
88-
except (tomli.TOMLDecodeError, OSError) as e:
93+
except (tomllib.TOMLDecodeError, OSError) as e:
8994
raise click.FileError(
9095
filename=str(path), hint=f"Error reading {path}:\n{e}"
9196
) from None
@@ -114,15 +119,15 @@ def read_config(
114119
115120
Raises
116121
------
117-
tomli.TOMLDecodeError
122+
tomllib.TOMLDecodeError
118123
Raised if ``*.toml`` could not be read.
119124
KeyError
120125
Raised if the specified sections do not exist.
121126
122127
"""
123128
sections_ = sections.split(".")
124129

125-
config = tomli.loads(path.read_text(encoding="utf-8"))
130+
config = tomllib.loads(path.read_text(encoding="utf-8"))
126131

127132
for section in sections_:
128133
config = config[section]

0 commit comments

Comments
 (0)