From f6142988fba0c8671ac9e0d36f005ea3e5e57763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 12 Oct 2022 17:05:45 +0200 Subject: [PATCH 1/2] Use the modern tomllib/tomli backends for reading TOML 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. --- pytest_pylint/plugin.py | 13 +++++++++---- setup.py | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pytest_pylint/plugin.py b/pytest_pylint/plugin.py index 7cc751d..b37cd77 100644 --- a/pytest_pylint/plugin.py +++ b/pytest_pylint/plugin.py @@ -4,6 +4,7 @@ """ +import sys from collections import defaultdict from configparser import ConfigParser, NoOptionError, NoSectionError from os import getcwd, makedirs, sep @@ -11,13 +12,17 @@ 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 @@ -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: diff --git a/setup.py b/setup.py index 748a511..4b36780 100644 --- a/setup.py +++ b/setup.py @@ -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=[ From ca95924b1b909cb4769404fc4ab88dc99773f175 Mon Sep 17 00:00:00 2001 From: Carson Gee Date: Thu, 5 Oct 2023 20:17:59 -0600 Subject: [PATCH 2/2] Update plugin.py --- pytest_pylint/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pytest_pylint/plugin.py b/pytest_pylint/plugin.py index 63c5f05..23e9403 100644 --- a/pytest_pylint/plugin.py +++ b/pytest_pylint/plugin.py @@ -21,6 +21,7 @@ if sys.version_info >= (3, 11): import tomllib else: + # pylint: disable=import-error import tomli as tomllib HISTKEY = "pylint/mtimes"