Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions language_tool_python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, cast

import toml

from ._compat import toml_loads
from .exceptions import LanguageToolError
from .server import LanguageTool

Expand All @@ -30,7 +29,7 @@
project_root = Path(__file__).resolve().parent.parent
pyproject = project_root / "pyproject.toml"
with pyproject.open("rb") as f:
__version__ = toml.loads(f.read().decode("utf-8"))["project"]["version"]
__version__ = toml_loads(f.read().decode("utf-8"))["project"]["version"]


logger = logging.getLogger(__name__)
Expand All @@ -40,7 +39,7 @@
) as config_path,
config_path.open("rb") as f,
):
log_config = toml.loads(f.read().decode("utf-8"))
log_config = toml_loads(f.read().decode("utf-8"))
dictConfig(log_config)


Expand Down
23 changes: 23 additions & 0 deletions language_tool_python/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Compatibility helpers for Python-version-dependent imports.

This module centralizes the fallback imports used across the package:

- ``deprecated``: built-in ``warnings.deprecated`` on Python 3.13+, otherwise
``typing_extensions.deprecated``.
- ``toml_loads``: built-in ``tomllib.loads`` on Python 3.11+, otherwise
``tomli.loads``.
Comment thread
mdevolde marked this conversation as resolved.
"""

import sys

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

if sys.version_info >= (3, 13):
from warnings import deprecated
else:
from typing_extensions import deprecated

__all__ = ["deprecated", "toml_loads"]
16 changes: 0 additions & 16 deletions language_tool_python/_deprecated.py

This file was deleted.

5 changes: 2 additions & 3 deletions language_tool_python/download_lt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
from warnings import warn

import requests
import toml
import tqdm
from packaging import version
from packaging.version import Version

from ._deprecated import deprecated
from ._compat import deprecated, toml_loads
from .exceptions import JavaError, PathError
from .safe_zip import SafeZipExtractor
from .utils import (
Expand Down Expand Up @@ -83,7 +82,7 @@
) as hashes_path,
hashes_path.open("rb") as f,
):
EXPECTED_DOWNLOAD_SHA256 = toml.loads(f.read().decode("utf-8"))
EXPECTED_DOWNLOAD_SHA256 = toml_loads(f.read().decode("utf-8"))

JAVA_VERSION_REGEX = re.compile(
r'^(?:java|openjdk) version "(?P<major1>\d+)(|\.(?P<major2>\d+)\.[^"]+)"',
Expand Down
2 changes: 1 addition & 1 deletion language_tool_python/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import total_ordering
from typing import TYPE_CHECKING

from ._deprecated import deprecated
from ._compat import deprecated
from .utils import SupportsFloat, SupportsInt

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion language_tool_python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import psutil
from packaging import version

from ._deprecated import deprecated
from ._compat import deprecated
from .exceptions import JavaError, PathError

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"tqdm",
"packaging",
"psutil",
"toml",
"tomli; python_version < '3.11'", # only needed for py < 3.11 because tomllib added in 3.11 is used in the codebase, needs a fallback
"typing_extensions; python_version < '3.13'", # only needed for py < 3.13 because warnings.deprecated added in 3.13 is used in the codebase
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import warnings

from language_tool_python._deprecated import deprecated
from language_tool_python._compat import deprecated

EXPECTED_CUSTOM_WARNING_RESULT = 42
EXPECTED_FUNCTION_SUM = 5
Expand Down
13 changes: 2 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading