refactor: drop Enum patch; raise TypeError when @deprecated is applied to a class#120
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the historical Enum-class workaround in @deprecated and makes class decoration an explicit error, pushing class-level deprecation to the dedicated @deprecated_class() proxy API.
Changes:
@deprecatednow raisesTypeErrorwhen applied to any class (Enum/dataclass/plain class), pointing users to@deprecated_class().- Removes the Enum wrapper/Enum-special-casing helpers and simplifies
_prepare_target_call. - Updates test fixtures and integration/unit tests to use
@deprecated_class()for Enums/dataclasses and to reflect proxy warning semantics.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/deprecate/deprecation.py |
Removes Enum wrapper patch, adds class-guard TypeError, refactors _prepare_target_call and call path |
tests/collection_deprecate.py |
Migrates deprecated Enum/dataclass fixtures from @deprecated to @deprecated_class (incl. self-mapped enum) |
tests/integration/test_classes.py |
Updates enum integration tests to match _DeprecatedProxy warning-on-access behavior and new fixtures |
tests/unittests/test_deprecation.py |
Replaces Enum helper unit tests with coverage for the new “class guard” TypeError behavior |
Borda
added a commit
that referenced
this pull request
Mar 2, 2026
Co-authored-by: Codex Agent <codex-agent@openai.com>
Borda
added a commit
that referenced
this pull request
Mar 3, 2026
…ied to a class `@deprecated` was designed for callables (functions/methods). Support for Enum classes was added in #104 as a Python 3.12 compatibility patch via `_DeprecatedEnumWrapper`, not by design. That workaround had a known flaw: `isinstance()` checks silently broke because the class binding was replaced by a wrapper object. Now that `@deprecated_class()` exists as the proper API for class-level deprecation, the patch is removed. Changes: - `packing()` raises `TypeError` for any class source (Enum, dataclass, plain class), with a message pointing to `@deprecated_class()` - Delete `_DeprecatedEnumWrapper`, `_is_enum_value_case`, `_convert_enum_value_args`, and `ENUM_VALUE_PARAM` - Simplify `_prepare_target_call`: drop `source_is_class` / `source_has_var_positional` params, return `Callable` not `tuple` - Migrate 9 `@deprecated`-on-class wrappers in the test collection to `@deprecated_class()` (7 Enums + 2 dataclasses) - Replace `TestIsEnumValueCase` / `TestConvertEnumValueArgs` unit tests with `TestDeprecatedClassGuard` covering the new TypeError behaviour - Update `TestDeprecatedEnums` to reflect proxy warning-on-attribute-access semantics (consistent with `_DeprecatedProxy` design) Co-Authored-By: Claude Code <noreply@anthropic.com>
for more information, see https://pre-commit.ci
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Codex Agent <codex-agent@openai.com>
Adjust expected expired-callable count at version 0.5 from 20 to 21 after recent wrapper additions.
- Rename `SelfMappedEnum` to `_SelfMappedEnum` for consistency with naming conventions for internal use. - Add `# type: ignore[call-arg]` annotations to address type-checking warnings in deprecated Enum test cases.
Borda
added a commit
that referenced
this pull request
Mar 3, 2026
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
src/deprecate/deprecation.py:521
- The TypeError message for applying
@deprecatedto a class points users to "@deprecated_class() from deprecate.proxy". Since deprecated_class is re-exported at the top-level (deprecate.deprecated_class), consider referencing the public import path (e.g., "use deprecate.deprecated_class" / "from deprecate import deprecated_class") to avoid steering users toward an internal submodule path.
if inspect.isclass(source):
raise TypeError(
f"Cannot apply @deprecated to class '{source.__name__}'. "
"For class-level deprecation use @deprecated_class() from deprecate.proxy."
)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Borda
added a commit
that referenced
this pull request
Mar 3, 2026
* docs: Dosu updates for PR #120 * Apply suggestions from code review * docs: soften @deprecated class guard notes — drop redundant WARNING, rewrite IMPORTANT as NOTE - Replace [!IMPORTANT] with [!NOTE] and rewrite as positive guidance ("use @deprecated_class()") rather than a TypeError scare - Remove the duplicate [!WARNING] block before the Enums/dataclasses section (the section itself already shows the correct approach) - Improve the __init__ docstring note to explain when to prefer each path - Fix the troubleshooting example: replace `pass # warns at instantiation time` with a real body that stores state and a clearer comment --------- Co-authored-by: dosubot[bot] <131922026+dosubot[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Borda
added a commit
that referenced
this pull request
Mar 3, 2026
- Skip signature-based invalid_args check for _DeprecatedProxy objects (proxy __call__ is (*args, **kwargs) so all args_mapping keys were falsely reported as invalid) - Suppress warnings during find_deprecated_callables scanning to prevent proxy __getattr__ from consuming num_warns budget - Add ChainedProxyColorEnum and depr_func_targeting_proxy fixtures for proxy→proxy and function→proxy chain detection testing - Add tests: skips_signature_validation, identity_mapping_detected, no_target_with_args_mapping, warning_budget, and 3 proxy chain tests - Fix test_all_proxy_types_pass_basic_validation: mapped proxy invalid_args expectation corrected from ["val"] / ["name","count"] / [...] to [] - Add _types.py to project structure tree in CONTRIBUTING.md - Fix RELEASE_0-5.md: replace inaccurate "Enum Signature Fix" with correct descriptions of #120 (class TypeError guard) and #121 (cross-class guard) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3 tasks
Borda
added a commit
that referenced
this pull request
Mar 3, 2026
- Skip signature-based invalid_args check for _DeprecatedProxy objects (proxy __call__ is (*args, **kwargs) so all args_mapping keys were falsely reported as invalid) - Suppress warnings during find_deprecated_callables scanning to prevent proxy __getattr__ from consuming num_warns budget - Add ChainedProxyColorEnum and depr_func_targeting_proxy fixtures for proxy→proxy and function→proxy chain detection testing - Add tests: skips_signature_validation, identity_mapping_detected, no_target_with_args_mapping, warning_budget, and 3 proxy chain tests - Fix test_all_proxy_types_pass_basic_validation: mapped proxy invalid_args expectation corrected from ["val"] / ["name","count"] / [...] to [] - Add _types.py to project structure tree in CONTRIBUTING.md - Fix RELEASE_0-5.md: replace inaccurate "Enum Signature Fix" with correct descriptions of #120 (class TypeError guard) and #121 (cross-class guard) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Codex Agent <codex-agent@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting
What does this PR do?
@deprecatedwas designed for callables (functions/methods). Support for Enum classes was added in #104 as a Python 3.12 compatibility patch via_DeprecatedEnumWrapper, not by design. That workaround had a known flaw:isinstance()checks silently broke because the class binding was replaced by a wrapper object. Now that@deprecated_class()exists as the proper API for class-level deprecation, the patch is removed.Changes:
packing()raisesTypeErrorfor any class source (Enum, dataclass, plain class), with a message pointing to@deprecated_class()_DeprecatedEnumWrapper,_is_enum_value_case,_convert_enum_value_args, andENUM_VALUE_PARAM_prepare_target_call: dropsource_is_class/source_has_var_positionalparams, returnCallablenottuple@deprecated-on-class wrappers in the test collection to@deprecated_class()(7 Enums + 2 dataclasses)TestIsEnumValueCase/TestConvertEnumValueArgsunit tests withTestDeprecatedClassGuardcovering the new TypeError behaviourTestDeprecatedEnumsto reflect proxy warning-on-attribute-access semantics (consistent with_DeprecatedProxydesign)Part of #109
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃