Repository navigation
v0.6.0: Deprecation Proxy for class/instances
🎉 pyDeprecate 0.6.0
pyDeprecate 0.6.0.post0 is the full proxy release — deprecated_class() and deprecated_instance() now cover the complete Python type hierarchy (Enum, dataclass, built-in types), isinstance()/issubclass() semantics work correctly on proxied classes, and the audit API is cleaner and more consistent.
🚀 Added
Deprecation Proxy for Enum, Dataclass, and Built-in Types.
deprecated_class() and deprecated_instance() now support the full Python type hierarchy via _DeprecatedProxy. Attribute access, method calls, and class behaviour all forward transparently to the underlying type.
from enum import Enum
from deprecate import deprecated_class
# NEW/FUTURE API
class Color(Enum):
RED = 1
BLUE = 2
# DEPRECATED API — transparent proxy, no class body to duplicate
OldColor = deprecated_class(Color, deprecated_in="0.6", remove_in="1.0")
OldColor.RED # FutureWarning: OldColor is deprecated, use Color
OldColor.RED.value # 1Also works for dataclass and plain built-in types. (#114)
Correct isinstance() / issubclass() Semantics on Proxies.
A deprecated_class() proxy can be used as the second argument to isinstance() or issubclass() and works exactly as expected. Without __instancecheck__/__subclasscheck__, using a proxy object (not a real type) as the right-hand argument raises TypeError. (#126)
assert isinstance(OldColor.RED, OldColor) # True
assert issubclass(Color, OldColor) # TrueNeither check emits a deprecation warning — type checks are structural and do not consume the warning budget.
🌱 Changed
@deprecated on a Class Now Delegates to deprecated_class().
Applying @deprecated directly to a class continues to work but now emits a UserWarning at decoration time and routes to deprecated_class() under the hood. This brings two concrete improvements over the v0.5.0 behaviour:
Warning-only (target=None) — now signals migration path:
from enum import Enum
from deprecate import deprecated
@deprecated(target=None, deprecated_in="0.5", remove_in="1.0")
class LMM(Enum):
FLORENCE_2 = "florence_2"
GPT_4O = "gpt_4o"Code like this continues to run. A UserWarning is now emitted at decoration time pointing to deprecated_class() as the dedicated API. (#132)
Forwarding (target=SomeClass) — fixes silent isinstance breakage:
In v0.5.0, @deprecated(NewColor, ...) class OldColor(Enum) used an internal _DeprecatedEnumWrapper that silently broke isinstance() checks — isinstance(x, OldColor) would raise TypeError or return the wrong result. The delegation to deprecated_class() replaces this with _DeprecatedProxy, which preserves isinstance/issubclass semantics correctly. (#132, #120)
# Recommended — use deprecated_class() directly for the cleanest result:
from deprecate import deprecated_class
OldColor = deprecated_class(Color, deprecated_in="0.6", remove_in="1.0")🗑️ Deprecated
Audit API Renamed for Consistency.
All three old audit names are wrapped @deprecated shims — they still work and forward to the new names, emitting a FutureWarning when called. They will be removed in v1.0.
| Old name | New name |
|---|---|
find_deprecated_callables |
find_deprecation_wrappers |
validate_deprecated_callable |
validate_deprecation_wrapper |
DeprecatedCallableInfo |
DeprecationWrapperInfo |
Before:
from deprecate import (
find_deprecated_callables,
validate_deprecated_callable,
DeprecatedCallableInfo,
)
wrappers: list[DeprecatedCallableInfo] = find_deprecated_callables(my_module)
validate_deprecated_callable(my_module.old_fn)After:
from deprecate import (
find_deprecation_wrappers,
validate_deprecation_wrapper,
DeprecationWrapperInfo,
)
wrappers: list[DeprecationWrapperInfo] = find_deprecation_wrappers(my_module)
validate_deprecation_wrapper(my_module.old_fn)Why: The old names used a deprecated_callable (past-tense adjective) pattern while the rest of the library uses deprecation_* (noun form). The rename aligns with DeprecationConfig, DeprecationWrapperInfo, and deprecated_class()/deprecated_instance(). (#125)
no_warning_call→assert_no_warnings. The test helper has been renamed to match theassertWarns/assertRaisesnaming convention from the standard library. The old name remains as a deprecated alias until v1.0.
Before:
from deprecate import no_warning_call
with no_warning_call():
call_stable_api()After:
from deprecate import assert_no_warnings
with assert_no_warnings():
call_stable_api()Why: assert_no_warnings mirrors assertWarns/assertRaises, making test intent immediately obvious at a glance. (#131)
🔧 Fixed
@deprecated with a Class target on a Non-__init__ Method Now Fails Fast.
This pattern was never documented or supported. Passing a class as target on a non-__init__ method caused @deprecated to silently instantiate the target class at call time and forward self of the wrong type into it — always a runtime bug, never a valid deprecation. The guard now raises TypeError at decoration time so the misconfiguration is caught immediately rather than at the first call. (#121)
Was silently wrong (never valid):
class OldService:
@deprecated(NewService, deprecated_in="0.5", remove_in="1.0")
def process(self): # ← TypeError raised here now
...
# Previously: instantiated NewService() and called it with self=OldService instance
# → AttributeError or worse at runtime on every callCorrect alternatives:
# 1. Rename within the same class — forward to the new method directly:
class MyService:
def process(self):
...
@deprecated(target=process, deprecated_in="0.6", remove_in="1.0")
def run(self):
...
# 2. Deprecate the whole class — use deprecated_class() on the class itself:
NewService = ...
OldService = deprecated_class(NewService, deprecated_in="0.6", remove_in="1.0")
# 3. Constructor forwarding — target=NewClass on __init__ remains valid:
class OldService(NewService):
@deprecated(NewService, deprecated_in="0.6", remove_in="1.0")
def __init__(self, x, y):
...find_deprecation_wrappers()no longer reports falseinvalid_argsfor proxy objects. The proxy__call__has a catch-all(*args, **kwargs)signature; allargs_mappingkeys were previously flagged as invalid. Signature validation is now skipped for proxy objects. (#124)
📦 Installation
pip install --upgrade pyDeprecate
# For audit features:
pip install --upgrade "pyDeprecate[audit]"🙏 Thank You
A big thank you to everyone who helped with this release:
- Jirka Borovec (@Borda) — proxy features, audit API rename, breaking-change guard, bug fixes, docs, and release management
Full Changelog: v0.5.0...v0.6.0.post0