From 15f53a5c6d9a90d99a7c17f020269177bd799ac3 Mon Sep 17 00:00:00 2001 From: maxb2 Date: Mon, 1 May 2023 18:07:37 -0500 Subject: [PATCH] fix: tomllib --- typer_config/loaders.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/typer_config/loaders.py b/typer_config/loaders.py index 137f0c5..11dfa0a 100644 --- a/typer_config/loaders.py +++ b/typer_config/loaders.py @@ -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 @@ -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