Skip to content

Commit

Permalink
Use the modern tomllib/tomli backends for reading TOML
Browse files Browse the repository at this point in the history
Replace the deprecated `toml` package with the built-in `tomllib`
module in Python 3.11, with fallback to the modern `tomli` package
in older Python versions.
  • Loading branch information
mgorny committed Nov 9, 2022
1 parent 804add7 commit f614298
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions pytest_pylint/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
"""


import sys
from collections import defaultdict
from configparser import ConfigParser, NoOptionError, NoSectionError
from os import getcwd, makedirs, sep
from os.path import dirname, exists, getmtime, join
from pathlib import Path

import pytest
import toml
from pylint import config as pylint_config
from pylint import lint

from .pylint_util import ProgrammaticReporter
from .util import PyLintException, get_rel_path, should_include_file

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

HISTKEY = "pylint/mtimes"
PYLINT_CONFIG_CACHE_KEY = "pylintrc"
FILL_CHARS = 80
Expand Down Expand Up @@ -184,10 +189,10 @@ def _load_rc_file(self, pylintrc_file):
pass

def _load_pyproject_toml(self, pylintrc_file):
with open(pylintrc_file, "r", encoding="utf-8") as f_p:
with open(pylintrc_file, "rb") as f_p:
try:
content = toml.load(f_p)
except (TypeError, toml.decoder.TomlDecodeError):
content = tomllib.load(f_p)
except (TypeError, tomllib.TOMLDecodeError):
return

try:
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
packages=["pytest_pylint"],
entry_points={"pytest11": ["pylint = pytest_pylint.plugin"]},
python_requires=">=3.7",
install_requires=["pytest>=5.4", "pylint>=2.3.0", "toml>=0.7.1"],
install_requires=[
"pytest>=5.4",
"pylint>=2.3.0",
"tomli>=1.1.0; python_version < '3.11'",
],
setup_requires=["pytest-runner"],
tests_require=["coverage", "flake8", "black", "isort"],
classifiers=[
Expand Down

0 comments on commit f614298

Please sign in to comment.