Repository navigation
v0.15.0: Dependency-free CLI, & CI integrations
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
pydeprecateCLI no longer pulls infireorrich. - Deprecated generators still work as pytest fixtures, and
import deprecategot 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=1The 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 summaryA 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-membersA 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; movepytest.warns/pytest.raisesaround 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 onlytrue,false,1or0; use the bare flag or--no-<flag>otherwise. (#243, #252) - CLI exit codes:
checkandallexit1on misconfigured targets and inner-order@property @deprecated; scan and internal errors exit3instead of1, and--exit-zeromasks neither2nor3. (#248, #252) args_mapping={"old_arg": ""}now silently keeps the argument under its old name, so a**kwargstarget receives it; map it toNoneto drop it. (#251)- Proxy type checks:
type(proxy) is _DeprecatedProxyis nowFalse; useisinstance(proxy, DeprecationProxy). Proxies only expose the protocols the wrapped object supports. (#257) deprecated_module(stream=None)now emits aFutureWarning: from v1.0stream=Nonesilences the module warning and thenum_warnsdefault becomes1. Omitstreamto 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.yamlwith one hook id per gate (check,policy,expiry,chains,all) plus thepydeprecatealias. (#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:
include_memberseverywhere:validate_deprecation_chainsandvalidate_mapping_compatibilityacceptinclude_members, andcheck,expiry,policy,chainsandallaccept--no-include-members. (#249, #252)
⚠️ Breaking Changes
- Partial sources:
functools.partial,partialmethodandsingledispatchmethodpassed as the deprecated source raiseTypeErrorat decoration; wrap them in a plaindef. (#250) - Function proxies on classes: a
deprecated_instanceover a plain function stored as a class attribute receivesself; usestaticmethod(...)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 namedcls→ 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
deprecateframe → the caller's line and module. (#250) - Custom
stream: retried afterTypeError→ called exactly once,stacklevel=passed only when accepted. (#250) - Warning messages: multi-argument renames re-listed spent arguments → only arguments within budget;
%(source_path)sin 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 honourskip_if. (#250) - Protocols: every optional protocol → only the protocols of the wrapped object or replacement;
type(proxy) is _DeprecatedProxyisFalse. (#257)
CLI
- Parser: Fire +
rich→ standard-libraryargparse;pip install pyDeprecateruns the CLI ([audit]still needed for version-based checks),cliextra kept empty,--no-<flag>negation, per-subcommand--help, Fire-only spellings exit2. (#252) - Exit codes: misconfigured targets and inner-order properties passed →
check/allexit1; scan and internal errors exit1→3; single.pyfile or multi-package directory → exit2. (#248, #252) - Audit gaps: free-form
Skipping …advisories → onepydeprecate gap: <kind>:stderr line per gap, including a newother copy auditedgap 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.proxyis 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→FutureWarningon every read. (#253)- Packaging: metadata in
setup.py→ PEP 621[project]inpyproject.toml; wheel declaresLicense-Expression: Apache-2.0. (#252)
🗑️ Deprecated
deprecated_module(stream=None): warns at the call; from v1.0 it silences the module warning andnum_warnsdefaults to1. Omitstreaminstead. (#253)DeprecationConfigcall-time cache fields (target_positional_only,source_var_positional_prefixand six more): internal, leavingDeprecationConfigin v1.0; read public fields viaget_deprecation_config(obj). Announced only, no runtime warning. (#253)deprecate.utils.get_func_arguments_types_defaultsand the names indeprecate.docstring.inject: internal despite their names, gaining a leading underscore in v1.0; useinspect.signatureandupdate_docstring=True. Announced only, no runtime warning. (#253)
🔧 Fixed
Call forwarding & signatures
- Calls that need no forwarding lost their positional / keyword form, breaking
singledispatchand patched-signature sources; forwarding tofunctools.partialand callable-instance targets failed; a failed warning spent the proxy budget. (#250) - On
*argssources, the deprecated name could win over an explicit new name, andargs_extrawas 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 generatorsinspect.isasyncgenfunction), so pytestyieldfixtures 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
UserWarningmore than once, and the module redirect guard reported false cycles across asyncio tasks and copied-context threads. (#251)
CLI & audit
allandstatusreportedversion not resolvedfor 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)expiryandchainsraisedValueErroron a plain directory of modules, and the scanned package saw the CLI's ownsys.argv. (#248)- A boolean flag before the path swallowed the path. (#243, #252)
--version 0.10was read as0.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
argparseCLI.
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.