Skip to content

Add LettuceDetectDeprecationWarning and a deprecation helper #135

Closed

Description

@hslev

Parent: #134 · Epic: #126 · Blocked by: none (follow 02 once merged)
Work on branch 134-see-one-consistent-warning-*; commit the changes and close the ticket.

Problem

Later tickets deprecate TransformerDetector, LLMDetector, make_detector, CacheManager, the predict* methods and two arguments. Each must warn the same way, with the same docstring note and the same type-checker marking. No such mechanism exists, and no real name is deprecated in this ticket.

Current behavior

  • lettucedetect/detectors/__init__.py:1-15 exports detectors only; there is no warning class and no deprecation code anywhere in lettucedetect/detectors/.
  • HallucinationDetector (outside this package) calls make_detector and predict*, so deprecated names called from inside lettucedetect must stay silent.

Steps

  1. Add lettucedetect/detectors/_deprecation.py: LettuceDetectDeprecationWarning(DeprecationWarning), constants DEPRECATED_SINCE and REMOVED_IN (clearly marked placeholders), a deprecated(replacement) decorator for classes, functions and methods, and a _UNSET sentinel plus a helper for deprecated arguments.
  2. The message reads exactly "X is deprecated since S and will be removed in R. Use U." using the constants.
  3. The decorator sets __deprecated__ (PEP 702), appends a .. deprecated:: note (replacement and removal version) to the docstring, and warns on each use with the caller's line as the attribution (stacklevel).
  4. A deprecated argument defaults to the sentinel; the helper warns only when the caller passed it.
  5. Skip the warning when the caller's module __name__ is lettucedetect or starts with lettucedetect..
  6. Export LettuceDetectDeprecationWarning from lettucedetect.detectors.
  7. Test on stand-ins defined in the test module.

Acceptance criteria

  • Subclass of DeprecationWarning; filtering other libraries' DeprecationWarning doesn't hide it and vice versa.
  • Messages are built from the constants in tests; no literal version numbers in tests.
  • Class, function and method uses warn once per call site under the default filter, attributed to the caller's line.
  • __deprecated__ and the docstring note are present.
  • Deprecated argument warns only when passed.
  • A call from a module named lettucedetect.* does not warn; the same call from a test module does.
  • A fresh-interpreter import lettucedetect.detectors emits no LettuceDetectDeprecationWarning.
  • Follows CONTRIBUTING "Errors and logging" (warnings.warn only for deprecations); existing tests pass.

Start here

uv run --extra dev pytest tests -q -x

Activity

  1. added
    ready-for-agent
    on Nov 5, 2026
  2. added theissue type on Nov 5, 2026
  3. hslev commented on Nov 6, 2026

    @hslev
    ContributorAuthor

    The decorator does not add the .. deprecated:: docstring note automatically; the module docstring treats it as a convention for whoever deprecates a name. A note appended to __doc__ at runtime would not reach the generated documentation or editor hovers, because both read docstrings from the source rather than from the imported object. That is why this change introduces a convention of writing the note explicitly into the docstring instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions