Repository navigation
Audit your deprecations without importing your package, gate whole monorepos in one run, and send the results to GitHub code scanning.
- Read source with
astusing--static, so CI needs none of your package's runtime dependencies. - Gate several packages in one run, and publish findings to code scanning with
--report-sarif. - Fail CI on any recorded gap with
--strict, and accept known findings with--ignoreor--baseline. - Point an old name at a new object with
deprecated_instance(target=...). - Call the import-free scan from Python with
find_deprecation_wrappers_static().
Mostly a drop-in upgrade; check one CLI spelling, the removed empty cli extra and stricter read_only proxies in the Migration guide.
✨ Spotlights / highlights
Audit a package without importing it
pydeprecate expiry and pydeprecate policy take --static, which reads the package source with ast and imports nothing, so a package can be audited without its runtime dependencies installed. It checks wrappers whose settings it can resolve. When it recognizes a form but cannot resolve it, it prints a pydeprecate gap: line instead of guessing; a few dynamic forms stay invisible, so a clean run is not proof of full coverage. The pydeprecate-expiry-static and pydeprecate-policy-static pre-commit hooks run the same checks, and find_deprecation_wrappers_static() returns the scan to Python as a frozen StaticScanResult that the expiry, policy and table helpers accept in place of a module. (#264, #267, #268)
pydeprecate expiry --static --strict src/mypackage# .pre-commit-config.yaml
repos:
- repo: https://github.com/Borda/pyDeprecate
rev: v0.16.0
hooks:
- id: pydeprecate-expiry-static
- id: pydeprecate-policy-staticStrict gates, known findings and monorepos
--strict (or strict = true in [tool.pydeprecate]) makes a run fail when part of the audit could not run; ignore, baseline and gate have [tool.pydeprecate] keys too. --ignore takes module:symbol or rule:module:symbol globs and --baseline takes an earlier --report-json file, so a project can adopt the audit without fixing everything first. Every subcommand now audits several paths in one run, each against its own version and pyproject.toml settings, and pydeprecate all --gate=policy fails on policy violations from the same scan. (#265, #266)
pydeprecate all --gate=policy src/pkg_a src/pkg_b
pydeprecate expiry src/mypackage --ignore='expired:mypackage.legacy:old_api'SARIF for code scanning and a richer GitHub Action
--report-sarif FILE writes SARIF 2.1.0 with one result per active finding, on every subcommand except status. The composite GitHub Action adds sarif and fail-on-gap inputs, a multi-line path, eight step outputs and finding annotations, at most 10 per level per step. (#265, #266, #267)
- uses: Borda/pyDeprecate@v0.16.0
id: pydeprecate
with:
subcommand: all
sarif: true
- uses: github/codeql-action/upload-sarif@v4
if: always() && steps.pydeprecate.outputs.sarif-file != ''
with:
sarif_file: ${{ steps.pydeprecate.outputs.sarif-file }}deprecated_instance forwards to a replacement object
deprecated_instance takes keyword-only target, args_mapping and attrs_mapping, the same options deprecated_class offers. The old name can now serve a new object, rename keyword arguments when it is called, and deprecate selected attributes. TargetMode.AUTO, True, False and a module as target raise TypeError. (#263)
from deprecate import deprecated_instance
def fetch_invoice(*, timeout):
return f"invoice fetched with timeout={timeout}"
class LegacyFetcher:
def __call__(self, *, wait):
return f"invoice fetched with wait={wait}"
old_fetch = deprecated_instance(
LegacyFetcher(),
name="old_fetch",
target=fetch_invoice,
args_mapping={"wait": "timeout"},
deprecated_in="0.16",
remove_in="1.0",
)
old_fetch(wait=5) # warns once, then calls fetch_invoice(timeout=5)🔄 Migration guide
A few CLI spellings and proxy behaviours change, so check the list below when you upgrade from v0.15.
Pass the version as --version. A second positional operand on expiry, all and status is read as a path first. If it is read as a version instead, it prints a stderr notice, and that form stops working in v1.0. After --, an operand is always a path, so pydeprecate expiry -- src/pkg 2.0 now treats 2.0 as a second path and exits 2 when no such path exists. A positional version together with --version exits 2. (#266)
# DEPRECATED API — still works with a stderr notice, removed in v1.0
pydeprecate expiry src/mypackage 2.0
# NEW API
pydeprecate expiry src/mypackage --version 2.0Replace pyDeprecate[cli] pins. The command needs no dependency since v0.15, so the empty cli extra is gone. pip install 'pyDeprecate[cli]' still installs, with pip's warning that the extra does not exist. Use the base package, or pyDeprecate[audit] for the expiry and grace-window checks. (#269)
# BEFORE (v0.15)
pip install 'pyDeprecate[cli]'
# AFTER (v0.16)
pip install 'pyDeprecate[audit]'read_only=True proxies block six more method names. sort, reverse, popitem, difference_update, intersection_update and symmetric_difference_update now raise AttributeError instead of changing the wrapped list, dict or set, and a custom method with one of these names is blocked too. (#273)
Count warnings per call, not per renamed keyword. A proxy with a callable target and args_mapping now draws on one call-level warning budget within the usual num_warns limit, and its message names the replacement rather than each renamed keyword. A test that counted or matched one warning per renamed keyword needs updating. (#273)
Name-based allowlists may need the function's own name. A function bound under several public names is now reported under the binding named like the function. An allowlist, --ignore pattern or snapshot that named an alias which used to sort first needs the function's own name. (#265)
📝 Notable changes
🚀 Added
- Import-free
--staticmode —pydeprecate expiryandpydeprecate policyaudit source withast;check,chains,allandstatusexit2with--static. (#264, #267) - Static pre-commit hooks —
pydeprecate-expiry-staticandpydeprecate-policy-static. (#264) find_deprecation_wrappers_static()andStaticScanResult— the import-free scan as a Python API, accepted byvalidate_deprecation_expiry,validate_deprecation_policyandgenerate_deprecation_table. (#268)--strict— a recordedpydeprecate gap:line exits1; each path in a multi-path run uses its own setting. (#265)--ignoreand--baseline— accept known findings by glob or by an earlier--report-jsonfile. (#265)--report-jsonfinding records —id,rule,level,messageandlocationper finding, plusgateandmode; the layout staysschema1 and a JSON Schema ships asdocs/schemas/report-1.schema.json. (#264, #265, #266)- Several paths per run — every subcommand audits any number of paths, and importing scans of several paths run in isolated worker processes. (#266)
pydeprecate all --gate=policy— fails on policy violations;gate = ["policy"]works in[tool.pydeprecate]. (#266)--report-sarif FILE— SARIF 2.1.0 for code scanning. (#266, #267)- GitHub Action inputs and outputs —
fail-on-gap,sarif, multi-linepath, step outputs and annotations. (#265, #266) deprecated_instanceforwards to a replacement — keyword-onlytarget,args_mappingandattrs_mapping. (#263)DeprecationConfig.call_options_inert— tells an inertargs_mappingorargs_extrafrom other misconfiguration. (#263)DeprecationWrapperInfo.source_fileandsource_line— where a wrapper is defined,Noneby default. (#265, #267)
🌱 Changed
- Misconfiguration:
args_mappingorargs_extraon a non-callable proxied object now emitUserWarningand mark the config misconfigured; warnings namedeprecated_instanceordeprecated_class. (#263) copy.copyof a proxy: shares a replacement → shallow-copies a non-class replacement object. (#263)- Audit: a non-callable proxy target is a
TARGETchain and reported by type, notstr(). (#263) - Version detection: an ancestor's version → the nearest
pyproject.tomlwith a[project]table owns it, and adynamicversion is read from the checkout ahead of stale installed metadata. (#264, #267) - Audit names: a function bound under several public names → reported under the binding named like itself. (#265)
--operand: possibly read as the legacy positional version → always a path. (#266)- Proxy warnings: one per renamed keyword → one call-level warning per call within
num_warns, naming the replacement, for a callable target withargs_mapping. (#273) read_only=True: 10 guarded method names → 16. (#273)deprecated_modulewith amessage_templateno longer warns about a missingdeprecated_in. (#273)
🗑️ Deprecated
- A second positional version on
expiry,allandstatus— use--version; the positional form is removed in v1.0. (#266) args_mappingorargs_extraon a non-callable proxied object — they warn now and raiseTypeErrorin v1.0; remove them or pass a callabletarget. (#263)
❌ Removed
- The empty
cliextra. The command needed no dependency since v0.15; install the base package orpyDeprecate[audit]. (#269)
🔧 Fixed
- A keyword named like a positional-only parameter stays a keyword when a call is rewritten for a callable with
**kwargs. (#263) - Matrix audit tables merge
1.0,v1.0and1.0.0into one column per release and order unparsed columns by their header. (#262) validate_deprecation_expiry(<module path>)without a version shows the package's real import error and keeps the caller's module path. (#262)- The
misconfigured-targetfinding namesATTRS_REMAPandARGS_REMAPcontradictions correctly. (#273) - A self-targeting
deprecated_classrename alias is no longer flaggedself_referenceorno_effect. (#273) - Report formatting and nested proxy construction no longer evaluate
skip_if; outside an audit,skip_ifis honoured across a proxy chain for__class__,__mro_entries__,isinstance,issubclassand operands. (#267) - A callable instance without
__name__is rejected with the plain-objectTypeErrorfromdeprecated_callable, not anAttributeError. (#267)
🏆 Contributors
- Jirka Borovec (@Borda, LinkedIn) —
deprecated_instanceforwarding, the import-free--staticaudit and Python API, strict mode, finding suppression, multi-path audits, SARIF reporting, CI and docs.
Automated contributions: dependabot, claude[bot], Codex, Copilot Autofix.
Full changelog: v0.15.0...v0.16.0
Co-authored with /oss:release.