Skip to content

Commit 77070a0

Browse files
committed
switch to tomli
1 parent 90523f6 commit 77070a0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

pylsp_mypy/plugin.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
from pathlib import Path
2121
from typing import IO, Any, Dict, List, Optional
2222

23-
import toml
23+
try:
24+
import tomllib
25+
except ModuleNotFoundError:
26+
import tomli as tomllib
27+
2428
from mypy import api as mypy_api
2529
from pylsp import hookimpl
2630
from pylsp.config.config import Config
@@ -400,7 +404,8 @@ def init(workspace: str) -> Dict[str, str]:
400404
)
401405
if path:
402406
if "pyproject.toml" in path:
403-
configuration = toml.load(path).get("tool").get("pylsp-mypy")
407+
with open(path, "rb") as file:
408+
configuration = tomllib.load(file).get("tool").get("pylsp-mypy")
404409
else:
405410
with open(path) as file:
406411
configuration = ast.literal_eval(file.read())
@@ -454,10 +459,13 @@ def findConfigFile(
454459
"instead."
455460
)
456461
if file.name == "pyproject.toml":
457-
configPresent = (
458-
toml.load(file).get("tool", {}).get("mypy" if mypy else "pylsp-mypy")
459-
is not None
460-
)
462+
with open(file, "rb") as fileO:
463+
configPresent = (
464+
tomllib.load(fileO)
465+
.get("tool", {})
466+
.get("mypy" if mypy else "pylsp-mypy")
467+
is not None
468+
)
461469
if not configPresent:
462470
continue
463471
if file.name == "setup.cfg":

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
python-lsp-server
22
mypy
3-
toml
4-
types-toml
3+
tomli >= 1.1.0 ; python_version < "3.11"
54
black
65
pre-commit
76
rstcheck

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ packages = find:
2121
install_requires =
2222
python-lsp-server >=1.7.0
2323
mypy
24-
toml
24+
tomli >= 1.1.0 ; python_version < "3.11"
2525

2626
[flake8]
2727
max-complexity = 20

0 commit comments

Comments
 (0)