Skip to content

v0.15.0: Dependency-free CLI, & CI integrations

Choose a tag to compare

@Borda Borda released this 09 Nov 11:02
· 12 commits to main since this release

Make deprecations fatal for exactly one block of code, and run the deprecation audit in CI as a hook or a single step.

  • Prove a test no longer touches deprecated APIs with as_exceptions(), scoped to one block, thread and task.
  • Add the audit as a pre-commit hook or a single GitHub Actions step.
  • Hand CI a machine-readable record of every scan with --report-json.
  • The pydeprecate CLI no longer pulls in fire or rich.
  • Deprecated generators still work as pytest fixtures, and import deprecate got faster.

Two breaking changes to handle: functools.partial-style sources and function proxies stored on classes. Also check generator warning timing, CLI spellings and exit codes; see the Migration guide.

✨ Spotlights / highlights

Scoped fatal deprecations

with deprecate.as_exceptions(): makes every pyDeprecate deprecation raise DeprecatedError for one block, then restores the previous setting on exit, including when the block raises. Scopes nest, as_exceptions(False) exempts an inner block (a wrapper's own as_exception=True stays fatal), and it also decorates a plain function. The setting lives in a ContextVar, so it stays local to the current thread and asyncio task and never changes deprecate.AS_EXCEPTIONS. (#240, #253)

import deprecate

with deprecate.as_exceptions():
    legacy_total([1, 2, 3])  # raises deprecate.DeprecatedError

with deprecate.as_exceptions(False):
    legacy_total([1, 2, 3])  # warns, even under DEPRECATE_AS_EXCEPTIONS=1

The audit CLI in pre-commit and GitHub Actions

The repository ships .pre-commit-hooks.yaml with one hook per gate (pydeprecate-check, pydeprecate-policy, pydeprecate-expiry, pydeprecate-chains, pydeprecate-all, plus pydeprecate as an alias of check) and a composite GitHub Action with the inputs subcommand, path, args, exit-zero, install and summary. Every subcommand also takes --report-json FILE, which writes the deprecation table and every audit gap as JSON on exit 0 or 1, and pydeprecate all --output FILE saves the table. (#243, #245)

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/Borda/pyDeprecate
    rev: v0.15.0
    hooks:
      - id: pydeprecate-check
        args: [--exit-zero]
# workflow job steps
- uses: Borda/pyDeprecate@v0.15.0
  with:
    path: src/mypackage
    summary: true # add a deprecation status table to the job summary

A dependency-free CLI

pydeprecate now runs on the standard library's argparse, without fire or rich, so pip install pyDeprecate starts it; add [audit] for the version-based expiry and grace-window checks, which need packaging. The cli extra stays, empty, so existing install lines keep working. Every subcommand has --help, boolean flags take a --no-<flag> form, and --no-include-members now reaches check, expiry, policy, chains and all. Option values stay strings, so --version 0.10 no longer turns into 0.1. (#249, #252)

pydeprecate check --exit-zero src/mypackage
pydeprecate all src/mypackage --version 0.10 --output table.md --report-json run.json
pydeprecate chains src/mypackage --no-include-members

A sturdier call path

The inner warning of a stacked deprecation chain, which reported a pyDeprecate frame, now points at the caller's line and module, as call-time warnings already did. Calls that need no forwarding reach the source with the caller's own arguments, so singledispatch functions and functools.wraps sources work, and forwarding to a functools.partial or callable-instance target works too. Deprecated generator functions stay generator functions, so a deprecated pytest yield fixture still runs its setup and teardown. import deprecate no longer loads the audit tooling, which roughly halves import time. (#250, #251, #256)

import warnings

# Key warning filters on the module that calls the deprecated API, not on pyDeprecate's own module.
warnings.filterwarnings("ignore", category=FutureWarning, module="myapp.legacy")

🔄 Migration guide

Two changes break code that worked on 0.14: one raises at decoration, the other changes what a class attribute receives. Several more change results, warning timing or CLI exit codes, so work through Also check below. No public name was removed.

functools.partial, partialmethod and singledispatchmethod sources raise TypeError at decoration. This includes a named partial that 0.14 accepted and then forwarded with the wrong result. Wrap the object in a plain def and deprecate that; forwarding to a partial target still works. (#250)

# BEFORE (v0.14)
legacy_scale = deprecated(target=scale, deprecated_in="1.0", remove_in="2.0")(
    update_wrapper(partial(scale, factor=2), scale)
)


# AFTER (v0.15)
@deprecated(target=scale, deprecated_in="1.0", remove_in="2.0")
def legacy_scale(value, factor=2):
    return void(value, factor)

A function deprecated_instance stored as a class attribute binds like a method. Instance access now passes self to a wrapped plain function or @deprecated wrapper. Wrap it in staticmethod(...) to keep static-style access. (#250)

# BEFORE (v0.14)
class Model:
    scale = deprecated_instance(scale_value, deprecated_in="1.0", remove_in="2.0")


# AFTER (v0.15)
class Model:
    scale = staticmethod(deprecated_instance(scale_value, deprecated_in="1.0", remove_in="2.0"))

Also check:

  • Warning filters: the inner warning of a stacked deprecation chain now carries the caller's module, so a filter keyed on module="deprecate" no longer matches them; key filters on the calling module. (#250)
  • Deprecated generators warn, bind arguments and raise fatal errors on the first next() / __anext__(), not at the call; move pytest.warns / pytest.raises around the first iteration. (#256)
  • CLI spellings that only Fire accepted now exit 2: quoted literals such as --version '"0.10"', list literals for --exclude (pass a comma-separated string), short flags such as -r, and a second positional path. A boolean flag given a value accepts only true, false, 1 or 0; use the bare flag or --no-<flag> otherwise. (#243, #252)
  • CLI exit codes: check and all exit 1 on misconfigured targets and inner-order @property @deprecated; scan and internal errors exit 3 instead of 1, and --exit-zero masks neither 2 nor 3. (#248, #252)
  • args_mapping={"old_arg": ""} now silently keeps the argument under its old name, so a **kwargs target receives it; map it to None to drop it. (#251)
  • Proxy type checks: type(proxy) is _DeprecatedProxy is now False; use isinstance(proxy, DeprecationProxy). Proxies only expose the protocols the wrapped object supports. (#257)
  • deprecated_module(stream=None) now emits a FutureWarning: from v1.0 stream=None silences the module warning and the num_warns default becomes 1. Omit stream to keep today's delivery. (#253)

📝 Notable changes

🚀 Added

Fatal deprecations

  • Scoped fatal deprecations: as_exceptions() context manager and decorator; nests, as_exceptions(False) exempts a block, local to the current thread and asyncio task. (#240, #253)

CLI & CI

  • pre-commit hooks: .pre-commit-hooks.yaml with one hook id per gate (check, policy, expiry, chains, all) plus the pydeprecate alias. (#243)
  • Composite GitHub Action: run any audit subcommand as one workflow step, with advisory mode and an optional job-summary table. (#245)
  • Scan output files:
    • --report-json FILE on every CLI subcommand: the scan's deprecation table plus every audit gap with a remedy hint, as JSON. (#245)
    • pydeprecate all --output FILE: save the appended deprecation table, as status --output does. (#245)
  • include_members everywhere: validate_deprecation_chains and validate_mapping_compatibility accept include_members, and check, expiry, policy, chains and all accept --no-include-members. (#249, #252)

⚠️ Breaking Changes

  • Partial sources: functools.partial, partialmethod and singledispatchmethod passed as the deprecated source raise TypeError at decoration; wrap them in a plain def. (#250)
  • Function proxies on classes: a deprecated_instance over a plain function stored as a class attribute receives self; use staticmethod(...) for static access. (#250)

🌱 Changed

Call forwarding & decoration

  • args_mapping={"old": ""} under @deprecated: argument dropped → kept under its old name. (#251)
  • Forwarding to a classmethod: receiver had to be named cls → any receiver name; malformed sources rejected at decoration. (#257)
  • Generator wrappers: warning, budget, skip_if, argument binding and fatal error at call time → at the first iteration. (#256)
  • Warning attribution: the inner warning of a stacked chain reported a deprecate frame → the caller's line and module. (#250)
  • Custom stream: retried after TypeError → called exactly once, stacklevel= passed only when accepted. (#250)
  • Warning messages: multi-argument renames re-listed spent arguments → only arguments within budget; %(source_path)s in proxy templates → module-qualified. (#251)

Proxies

  • Warning timing: warn after async operations, iteration steps and failed context entry → warn when the awaitable is obtained, before next() advances, and unwind the context on failure; fatal proxies refuse reads before touching the wrapped object; item and in-place writes honour skip_if. (#250)
  • Protocols: every optional protocol → only the protocols of the wrapped object or replacement; type(proxy) is _DeprecatedProxy is False. (#257)

CLI

  • Parser: Fire + rich → standard-library argparse; pip install pyDeprecate runs the CLI ([audit] still needed for version-based checks), cli extra kept empty, --no-<flag> negation, per-subcommand --help, Fire-only spellings exit 2. (#252)
  • Exit codes: misconfigured targets and inner-order properties passed → check / all exit 1; scan and internal errors exit 1 → 3; single .py file or multi-package directory → exit 2. (#248, #252)
  • Audit gaps: free-form Skipping … advisories → one pydeprecate gap: <kind>: stderr line per gap, including a new other copy audited gap when the import resolved outside the scanned directory; the scan header names the file it imported from. (#245, #248)

Modules, imports & packaging

  • import deprecate: loaded the audit tooling → loads it lazily; deprecate.proxy is now a package with unchanged import paths. (#251)
  • Public modules: no __all__ → __all__ declared, so star imports bind only public names. (#253)
  • DeprecationWrapperInfo.empty_mapping / identity_mapping: DeprecationWarning → FutureWarning on every read. (#253)
  • Packaging: metadata in setup.py → PEP 621 [project] in pyproject.toml; wheel declares License-Expression: Apache-2.0. (#252)

🗑️ Deprecated

  • deprecated_module(stream=None): warns at the call; from v1.0 it silences the module warning and num_warns defaults to 1. Omit stream instead. (#253)
  • DeprecationConfig call-time cache fields (target_positional_only, source_var_positional_prefix and six more): internal, leaving DeprecationConfig in v1.0; read public fields via get_deprecation_config(obj). Announced only, no runtime warning. (#253)
  • deprecate.utils.get_func_arguments_types_defaults and the names in deprecate.docstring.inject: internal despite their names, gaining a leading underscore in v1.0; use inspect.signature and update_docstring=True. Announced only, no runtime warning. (#253)

🔧 Fixed

Call forwarding & signatures

  • Calls that need no forwarding lost their positional / keyword form, breaking singledispatch and patched-signature sources; forwarding to functools.partial and callable-instance targets failed; a failed warning spent the proxy budget. (#250)
  • On *args sources, the deprecated name could win over an explicit new name, and args_extra was not injected for callers already using new names. (#251)
  • Forwarding replaced the target's own signature error with a misleading keyword error, and a docless deprecated class exposed internal proxy text as its __doc__. (#251)
  • Decorated callables were never garbage-collected, and a source default with a misbehaving __ne__ crashed a forwarded call. (#251)
  • Deprecated generator functions lost inspect.isgeneratorfunction (async generators inspect.isasyncgenfunction), so pytest yield fixtures skipped setup and teardown. (#256)

Proxies & concurrency

  • Instances of a class deprecated in place failed to pickle, copy or deepcopy. (#257)
  • Concurrent first calls could emit the misconfiguration UserWarning more than once, and the module redirect guard reported false cycles across asyncio tasks and copied-context threads. (#251)

CLI & audit

  • all and status reported version not resolved for a package with only __version__, and the audit API missed packages whose distribution name differs from the import name; every gate now shares one resolver. (#245, #246)
  • expiry and chains raised ValueError on a plain directory of modules, and the scanned package saw the CLI's own sys.argv. (#248)
  • A boolean flag before the path swallowed the path. (#243, #252)
  • --version 0.10 was read as 0.1, so expiry checks compared against the wrong release. (#252)
  • A submodule calling sys.exit() ended the whole recursive audit scan. (#252)

🏆 Contributors

  • Jirka Borovec (@Borda, LinkedIn) — scoped fatal deprecations, the pre-commit hooks and GitHub Action for the audit CLI, and a dependency-free argparse CLI.

Automated contributions: @dependabot, @pre-commit-ci, kilo-code-bot, Codex, Claude, Copilot coding agent, Copilot Autofix


Full changelog: v0.14.0...v0.15.0
Co-authored with /oss:release.