Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/docformatter/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@

# Standard Library Imports
import argparse
import contextlib
import os
import sys
from configparser import ConfigParser
from typing import Dict, Sequence, Union

with contextlib.suppress(ImportError):
try:
if sys.version_info >= (3, 11):
# Standard Library Imports
import tomllib
else:
# Third Party Imports
import tomli as tomllib
except ImportError:
# Neither the stdlib tomllib (Python < 3.11) nor the tomli backport is
# available; TOML configuration files are skipped in that case. See #368.
tomllib = None

# docformatter Package Imports
from docformatter import __pkginfo__
Expand Down Expand Up @@ -340,6 +343,11 @@ def _do_read_configuration_file(self) -> None:

def _do_read_toml_configuration(self) -> None:
"""Load configuration information from a *.toml file."""
if tomllib is None:
# tomli/tomllib is not installed (Python < 3.11 without the tomli
# backport); skip reading TOML configuration rather than crashing
# with a NameError. See #368.
return
with open(self.config_file, "rb") as f:
config = tomllib.load(f)

Expand Down
Loading