Skip to content

Commit

Permalink
fix: tomllib
Browse files Browse the repository at this point in the history
  • Loading branch information
maxb2 committed May 1, 2023
1 parent 64868a3 commit 15f53a5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions typer_config/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

from typing import Any, Dict

USING_TOMLLIB = False

try:
# Only available for python>=3.11
import tomllib as toml

USING_TOMLLIB = True
except ImportError:
try:
# Third-party toml parsing library
Expand Down Expand Up @@ -95,7 +99,11 @@ def toml_loader(path: str) -> Dict[str, Any]:
dictionary loaded from file
"""

with open(path, "r", encoding="utf-8") as _file:
conf = toml.load(_file)
if USING_TOMLLIB:
with open(path, "rb") as _file:
conf = toml.load(_file)
else:
with open(path, "r", encoding="utf-8") as _file:
conf = toml.load(_file)

return conf

0 comments on commit 15f53a5

Please sign in to comment.