Skip to content

See one consistent warning for every deprecated name (#134) - #186

Merged
hslev merged 2 commits into
stateless_corefrom
134-see-one-consistent-warning-for-every-deprecated-name
Nov 6, 2026
Merged

hslev merged 2 commits into
stateless_corefrom
134-see-one-consistent-warning-for-every-deprecated-name

Conversation

@hslev

@hslev hslev commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds one consistent deprecation mechanism and makes new code fail its tests if it calls a deprecated name. No real name is deprecated here: the behaviour is shown on stand-ins defined in the tests.

Deprecation utility (lettucedetect/detectors/_deprecation.py, from #135)

  • LettuceDetectDeprecationWarning(DeprecationWarning), exported from lettucedetect.detectors.
  • deprecated(replacement) decorator for classes, functions and methods. It wraps typing_extensions.deprecated, so each use warns once per call site, attributed to the caller's line, and sets __deprecated__ (PEP 702). Type checkers see it as the standard decorator.
  • _UNSET sentinel and warn_if_passed(value, name, replacement) for deprecated arguments; they warn only when the caller passed the argument.
  • Every message reads "X is deprecated since S and will be removed in R. Use U.", with S and R taken from DEPRECATED_SINCE and REMOVED_IN.
  • Calls from a module named lettucedetect or lettucedetect.* stay silent, so internal callers such as the HallucinationDetector facade do not warn.
  • typing_extensions>=4.5.0 is added as a dependency in pyproject.toml.
  • The .. deprecated:: docstring note is a convention for whoever deprecates a name (documented in the module docstring); the decorator does not add it automatically.

Warning as a test error (#136)

  • pyproject.toml: add filterwarnings = ["error::lettucedetect.detectors._deprecation.LettuceDetectDeprecationWarning"] to the pytest config.
  • Add one module-level pytestmark that ignores the warning to each of the five modules that call old names: test_inference_pytest.py, test_llm_detector_pytest.py, test_llm_client_pytest.py, test_custom_taxonomy_pytest.py, test_factory_pytest.py. No other edits in them.
  • tests/test_deprecation_pytest.py: tests for the helper on stand-ins, including that an unmarked call raises under the filter and pytest.warns still records the warning.

Related issue

Closes #135 and #136. Part of #134 (epic #126).

Type of change

  • Bug fix
  • Feature
  • Documentation
  • Tests
  • Refactor or maintenance

Testing

  • ruff format --check lettucedetect/ lettucedetect_api/ tests/
  • ruff check lettucedetect/ lettucedetect_api/ tests/ --extend-exclude lettucedetect/integrations/
  • python -m pytest
  • Other: uv run --extra dev pytest tests -q gives 216 passed.

Checklist

  • I kept the PR focused on one change.
  • I added or updated tests/docs when needed.
  • I checked that no secrets, API keys, or credentials are included.

Rights & sign-off (required)

  • I certify that I have the right to submit this code and that it may be
    distributed under the repository's MIT license
    (see CONTRIBUTING).

@hslev
hslev requested a review from adaamko November 6, 2026 09:53
@hslev
hslev merged commit d3c6dcc into stateless_core Nov 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant