Skip to content

refactor: drop Enum patch; raise TypeError when @deprecated is applied to a class#120

Merged
Borda merged 13 commits into
mainfrom
prune/emun
Mar 3, 2026
Merged

refactor: drop Enum patch; raise TypeError when @deprecated is applied to a class#120
Borda merged 13 commits into
mainfrom
prune/emun

Conversation

@Borda

@Borda Borda commented Mar 2, 2026

Copy link
Copy Markdown
Owner
Before submitting
  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

@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)

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 🙃

Copilot AI review requested due to automatic review settings March 2, 2026 21:53
@dosubot dosubot Bot added the tests label Mar 2, 2026
Comment thread tests/unittests/test_deprecation.py Fixed
@dosubot

dosubot Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • @deprecated now raises TypeError when 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

Comment thread src/deprecate/deprecation.py Outdated
Comment thread src/deprecate/deprecation.py
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Borda added a commit that referenced this pull request Mar 2, 2026
Co-authored-by: Codex Agent <codex-agent@openai.com>
@Borda Borda requested a review from Copilot March 2, 2026 22:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread tests/unittests/test_deprecation.py Outdated
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Comment thread tests/unittests/test_deprecation.py Fixed
Borda added a commit that referenced this pull request Mar 3, 2026
Borda and others added 8 commits March 3, 2026 01:15
…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>
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @deprecated to 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."
            )

Comment thread tests/collection_deprecate.py
Comment thread src/deprecate/deprecation.py
Comment thread src/deprecate/deprecation.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/deprecate/deprecation.py
@Borda Borda merged commit 55c719b into main Mar 3, 2026
34 checks passed
@Borda Borda deleted the prune/emun branch March 3, 2026 00:48
dosubot Bot added a commit that referenced this pull request Mar 3, 2026
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants