From e9d2d85f7847de2870826e98d41f4f8becdf98ed Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Tue, 22 Nov 2022 14:11:01 +0100 Subject: [PATCH] Read `toml` files using the standard `tomlib` (if available). #143 --- benedict/serializers/toml.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/benedict/serializers/toml.py b/benedict/serializers/toml.py index 67e23ce..ea37856 100644 --- a/benedict/serializers/toml.py +++ b/benedict/serializers/toml.py @@ -2,6 +2,14 @@ import toml +try: + # python >= 3.11 + import tomllib + + tomllib_available = True +except ImportError: + tomllib_available = False + from benedict.serializers.abstract import AbstractSerializer @@ -18,7 +26,10 @@ class TOMLSerializer(AbstractSerializer): ) def decode(self, s, **kwargs): - data = toml.loads(s, **kwargs) + if tomllib_available: + data = tomllib.loads(s, **kwargs) + else: + data = toml.loads(s, **kwargs) return data def encode(self, d, **kwargs):