Skip to content

feat: accept staticmethod/classmethod descriptors as target#192

Open
Borda wants to merge 8 commits into
mainfrom
fix/staticmethod
Open

feat: accept staticmethod/classmethod descriptors as target#192
Borda wants to merge 8 commits into
mainfrom
fix/staticmethod

Conversation

@Borda

@Borda Borda commented Jun 6, 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?

_normalize_target now unwraps staticmethod and classmethod objects passed as target, extracting .__func__ before forwarding to the callable path. Enables target=bbb inside a class body where bbb is still the raw descriptor, removing the need for target=bbb.__func__.

  • Add descriptor unwrap branch in _normalize_target (staticmethod + classmethod)
  • Extend target type annotation on deprecated(), _normalize_target, _raise_warn_callable, _build_call_plan to include staticmethod | classmethod
  • Add ServiceCls.old_static_redirect and old_static_redirect_mapped fixtures in collection_deprecate.py
  • Add TestStaticMethodDescriptorTarget (3 tests) in test_property.py
  • Add use-cases doc subsection for same-class static forwarding with and without args_mapping
  • Add no-redundant-naming test rule to AGENTS.md

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 🙃

`_normalize_target` now unwraps `staticmethod` and `classmethod` objects
passed as `target`, extracting `.__func__` before forwarding to the
callable path. Enables `target=bbb` inside a class body where `bbb` is
still the raw descriptor, removing the need for `target=bbb.__func__`.

- Add descriptor unwrap branch in `_normalize_target` (staticmethod + classmethod)
- Extend `target` type annotation on `deprecated()`, `_normalize_target`, `_raise_warn_callable`, `_build_call_plan` to include `staticmethod | classmethod`
- Add `ServiceCls.old_static_redirect` and `old_static_redirect_mapped` fixtures in `collection_deprecate.py`
- Add `TestStaticMethodDescriptorTarget` (3 tests) in `test_property.py`
- Add use-cases doc subsection for same-class static forwarding with and without `args_mapping`
- Add no-redundant-naming test rule to AGENTS.md

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 6, 2026 19:22
@dosubot dosubot Bot added documentation Improvements or additions to documentation enhancement New feature or request tests labels Jun 6, 2026
Comment thread tests/unittests/test_property.py Dismissed
@kilo-code-bot

kilo-code-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • AGENTS.md — Link text fix for Test Organization section
  • CHANGELOG.md — Changelog entry for staticmethod/classmethod descriptor target support
  • docs/guide/use-cases.md — New use-case documentation for staticmethod/classmethod forwarding
  • docs/llms.txt — Decision flowchart updated for descriptor target pattern
  • src/deprecate/deprecation.py — Core implementation for descriptor target unwrapping
  • tests/collection_deprecate.py — Test targets for staticmethod/classmethod descriptor forwarding
  • tests/unittests/test_property.py — Test classes for descriptor target support

Incremental check: Verified changes since previous review (commit f5023e3). All changes are non-code improvements:

  • AGENTS.md link text now correctly matches the CONTRIBUTING.md section anchor
  • CHANGELOG.md documents the new descriptor target feature
  • docs/guide/use-cases.md adds use-case example with proper <details><summary>Output: <code>…</code></summary> blocks
  • docs/llms.txt decision flowchart updated with descriptor target pattern and anti-pattern note
  • tests/collection_deprecate.py: New targets follow the three-layer separation pattern (targets in collection_deprecate.py, NOT in test files)
  • tests/unittests/test_property.py: New test classes follow naming conventions; all methods have proper scenario descriptions in docstrings

No new code issues detected.


Reviewed by laguna-m.1-20260312:free · 1,151,287 tokens

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 extends pyDeprecate’s call-forwarding to accept raw staticmethod/classmethod descriptor objects as target (e.g. using target=bbb inside a class body), by unwrapping descriptors to their underlying .__func__ during target normalization.

Changes:

  • Unwrap staticmethod / classmethod targets in _normalize_target() and widen target type annotations accordingly.
  • Add test coverage and new collection fixtures for staticmethod descriptor-target forwarding (including args_mapping).
  • Document the new “same-class staticmethod forwarding without .__func__” use-case and add an agent/testing guideline note.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/deprecate/deprecation.py Adds descriptor unwrapping in _normalize_target and updates target type annotations.
tests/unittests/test_property.py Adds unit tests validating forwarding behavior when target is a raw staticmethod descriptor.
tests/collection_deprecate.py Adds ServiceCls staticmethod wrappers that forward via descriptor targets (and with args_mapping).
docs/guide/use-cases.md Documents same-class staticmethod forwarding using target=<descriptor> without .__func__.
AGENTS.md Adds a “no redundant naming” test naming rule and a reference link to CONTRIBUTING.

Comment thread tests/unittests/test_property.py
Comment thread tests/unittests/test_property.py Outdated
Comment thread src/deprecate/deprecation.py
Comment thread src/deprecate/deprecation.py
Comment thread AGENTS.md Outdated
Comment thread docs/guide/use-cases.md Outdated
Borda and others added 6 commits June 6, 2026 14:30
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…descriptor targets

- Add descriptor unwrap in `_raise_warn_callable` before `callable(target)` check:
  `callable(staticmethod(fn))` is False on Py3.9 and `callable(classmethod(fn))` is
  always False, so without this fix the no-target warning template fires incorrectly
  (target name omitted from FutureWarning message).
- Add decoration-time TypeError guard in `_normalize_target` for asymmetric classmethod
  usage: when `classmethod.__func__` is the target but source has no `cls` parameter,
  `cls` would be missing at call time; now raises at decoration time with a clear message.
- Fix cross-class guard to inspect `__func__` for descriptor targets: raw descriptor
  lacks `__qualname__` on the instance, so the guard now unwraps before comparing.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…s to use collection fixtures

- Add `ServiceCls.old_class_redirect` and `old_class_redirect_mapped` to collection_deprecate.py —
  classmethod descriptor forwarding fixtures mirroring the staticmethod equivalents.
- Add `TestClassMethodDescriptorTarget` (4 tests): forwards_call, with_args_mapping,
  no_decoration_time_warning, and asymmetric_raises_at_decoration_time (verifies the new
  TypeError guard in `_normalize_target`).
- Refactor `TestStaticMethodDescriptorTarget.test_forwards_call` and `test_with_args_mapping`
  to use `ServiceCls` collection fixtures (three-layer rule); keep `test_no_decoration_time_warning`
  inline (it tests class-body evaluation, not call time).
- Add `match="in favor of"` and target-name assertions to forwarding tests — verifies the
  `_raise_warn_callable` fix (warning message now names the target on all Python versions).

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…descriptor target support

---
Co-authored-by: Claude Code <noreply@anthropic.com>
…o Decision Flowchart

Agents reading the flowchart now learn that target=new_method (raw descriptor in class
body) is the correct form — no .__func__ needed. Documents the classmethod symmetric-only
constraint and adds an anti-pattern entry for manual .__func__ access.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Comment thread tests/unittests/test_property.py Dismissed
Comment thread tests/unittests/test_property.py Dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants