Skip to content

Commit 0a8e62f

Browse files
authored
Merge pull request #40 from mgorny/tomli
Replace the obsolete toml package with tomllib/tomli
2 parents e96209c + 80d34ca commit 0a8e62f

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
rev: v1.3.0
1818
hooks:
1919
- id: mypy
20-
additional_dependencies: [black, types-pkg_resources, types-setuptools, types-toml]
20+
additional_dependencies: [black, types-pkg_resources, types-setuptools]
2121
- repo: https://github.com/pre-commit/pre-commit-hooks
2222
rev: v4.4.0
2323
hooks:

pylsp_black/plugin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import logging
22
import os
3+
import sys
34
from functools import lru_cache
45
from pathlib import Path
56
from typing import Dict, Optional
67

78
import black
8-
import toml
99
from pylsp import hookimpl
1010
from pylsp._utils import get_eol_chars
1111
from pylsp.config.config import Config
1212

13+
if sys.version_info >= (3, 11):
14+
import tomllib
15+
else:
16+
import tomli as tomllib
17+
1318
logger = logging.getLogger(__name__)
1419

1520

@@ -155,8 +160,9 @@ def _load_config(filename: str, client_config: Config) -> Dict:
155160
return defaults
156161

157162
try:
158-
pyproject_toml = toml.load(str(pyproject_filename))
159-
except (toml.TomlDecodeError, OSError):
163+
with open(pyproject_filename, "rb") as f:
164+
pyproject_toml = tomllib.load(f)
165+
except (tomllib.TOMLDecodeError, OSError):
160166
logger.warning(
161167
"Error decoding pyproject.toml, using defaults: %r",
162168
defaults,

setup.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ classifiers =
1818

1919
[options]
2020
packages = find:
21-
install_requires = python-lsp-server>=1.4.0; black>=22.3.0; toml
21+
install_requires =
22+
python-lsp-server>=1.4.0
23+
black>=22.3.0
24+
tomli; python_version<'3.11'
2225
python_requires = >= 3.7
2326

2427
[options.entry_points]
2528
pylsp = pylsp_black = pylsp_black.plugin
2629

2730
[options.extras_require]
2831
# add any types-* packages to .pre-commit-config.yaml mypy additional_dependencies
29-
dev = isort>=5.0; flake8; pre-commit; pytest; mypy; pytest; types-pkg_resources; types-setuptools; types-toml
32+
dev = isort>=5.0; flake8; pre-commit; pytest; mypy; pytest; types-pkg_resources; types-setuptools
3033

3134
[flake8]
3235
max-line-length = 88

0 commit comments

Comments
 (0)