Skip to content

Commit 5e136e6

Browse files
committedAug 2, 2021
Fix deprecation warning from tomli
1 parent 380c03b commit 5e136e6

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed
 

‎isort/settings.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,16 @@ def _find_config(path: str) -> Tuple[str, Dict[str, Any]]:
769769
def _get_config_data(file_path: str, sections: Tuple[str]) -> Dict[str, Any]:
770770
settings: Dict[str, Any] = {}
771771

772-
with open(file_path, encoding="utf-8") as config_file:
773-
if file_path.endswith(".toml"):
774-
config = tomli.load(config_file)
775-
for section in sections:
776-
config_section = config
777-
for key in section.split("."):
778-
config_section = config_section.get(key, {})
779-
settings.update(config_section)
780-
else:
772+
if file_path.endswith(".toml"):
773+
with open(file_path, "rb") as bin_config_file:
774+
config = tomli.load(bin_config_file)
775+
for section in sections:
776+
config_section = config
777+
for key in section.split("."):
778+
config_section = config_section.get(key, {})
779+
settings.update(config_section)
780+
else:
781+
with open(file_path, encoding="utf-8") as config_file:
781782
if file_path.endswith(".editorconfig"):
782783
line = "\n"
783784
last_position = config_file.tell()
@@ -790,22 +791,22 @@ def _get_config_data(file_path: str, sections: Tuple[str]) -> Dict[str, Any]:
790791

791792
config = configparser.ConfigParser(strict=False)
792793
config.read_file(config_file)
793-
for section in sections:
794-
if section.startswith("*.{") and section.endswith("}"):
795-
extension = section[len("*.{") : -1]
796-
for config_key in config.keys():
797-
if (
798-
config_key.startswith("*.{")
799-
and config_key.endswith("}")
800-
and extension
801-
in map(
802-
lambda text: text.strip(), config_key[len("*.{") : -1].split(",") # type: ignore # noqa
803-
)
804-
):
805-
settings.update(config.items(config_key))
806-
807-
elif config.has_section(section):
808-
settings.update(config.items(section))
794+
for section in sections:
795+
if section.startswith("*.{") and section.endswith("}"):
796+
extension = section[len("*.{") : -1]
797+
for config_key in config.keys():
798+
if (
799+
config_key.startswith("*.{")
800+
and config_key.endswith("}")
801+
and extension
802+
in map(
803+
lambda text: text.strip(), config_key[len("*.{") : -1].split(",") # type: ignore # noqa
804+
)
805+
):
806+
settings.update(config.items(config_key))
807+
808+
elif config.has_section(section):
809+
settings.update(config.items(section))
809810

810811
if settings:
811812
settings["source"] = file_path

0 commit comments

Comments
 (0)
Please sign in to comment.