Skip to content

feat(decorators): attach Hook*Configuration objects on marked functions - #7

Open
RonnyPfannschmidt wants to merge 1 commit into
refactor/configuration-objectsfrom
refactor/markers-attach-config
Open

feat(decorators): attach Hook*Configuration objects on marked functions#7
RonnyPfannschmidt wants to merge 1 commit into
refactor/configuration-objectsfrom
refactor/markers-attach-config

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Review PR — step 3 of 7.

This PR targets the previous step's branch, so its diff is only this step's change. Review happens here. The corresponding upstream PR, which is the one that actually merges, is pytest-dev#706.

Merges happen upstream one step at a time, bottom-up. When step 3 lands upstream, this PR is closed and the rest of the stack is rebased onto the new main.

Step Branch Review (downstream) Merge (upstream)
1 refactor/split-hook-modules #6 pytest-dev#703
2 refactor/configuration-objects #5 pytest-dev#704
3 refactor/markers-attach-config #7 pytest-dev#706
4 refactor/hookimpl-wrapper-types #8 pytest-dev#707
5 refactor/hookcaller-and-execution #9 pytest-dev#708
6 refactor/project-spec #10 pytest-dev#709
7 refactor/async-submitter #11 pytest-dev#710

Chain step 03 of the internal-refactoring series (design/03-markers-attach-config.md).

Stores the spec configuration as HookSpec.config (deprecated .opts alias kept), reads .config in firstresult resolution, and adds decoration-time historic+firstresult validation tests.

Stacked on #5.

🤖 Generated with Claude Code

Summary by Sourcery

Attach and expose hook specification configuration objects on marked functions and shift usage from the deprecated opts attribute to config, including validation and tests for historic/firstresult behavior.

New Features:

  • Store HookspecConfiguration as HookSpec.config on hook specifications and expose it via pm.hook..spec.

Enhancements:

  • Add decoration-time validation to forbid hooks that are both historic and firstresult.
  • Update hook calling logic to read firstresult from HookSpec.config instead of the deprecated opts attribute.
  • Provide a deprecated HookSpec.opts property as an alias to config for backward compatibility.

Tests:

  • Extend configuration tests to cover stored spec configuration and decoration-time errors for invalid historic/firstresult combinations.
  • Update hook caller tests to assert firstresult behavior via the new HookSpec.config attribute.

Chores:

  • Add a trivial changelog entry documenting the refactoring of hook specification configuration storage.

@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors hook specification storage to use a HookspecConfiguration object on HookSpec.config (with a deprecated .opts alias), updates hook caller logic to read configuration from .config, and adds tests to validate historic+firstresult configuration at decoration time and that specs are correctly storing configuration.

File-Level Changes

Change Details Files
HookSpec now stores its configuration in a config attribute instead of opts, with a deprecated opts property alias.
  • Change HookSpec.slots to replace opts with config.
  • Update HookSpec.init to accept a config parameter, assign it to self.config, and derive warn_on_impl and warn_on_impl_args from it.
  • Add a deprecated opts @Property that returns self.config and documents the alias.
src/pluggy/_decorators.py
HookCaller now resolves firstresult using HookSpec.config instead of HookSpec.opts.
  • Update call to read firstresult from self.spec.config.firstresult when a spec is present.
  • Update call_extra to read firstresult from self.spec.config.firstresult when a spec is present.
src/pluggy/_caller.py
Tests are added/updated to validate configuration storage on specs and decoration-time validation of historic+firstresult.
  • Add a test ensuring that marking a hook specification as both historic and firstresult raises ValueError at decoration time.
  • Add a test verifying that PluginManager-attached specs expose a HookspecConfiguration via spec.config, and that the deprecated spec.opts alias points to the same object.
  • Update existing tests to assert firstresult through spec.config.firstresult instead of spec.opts.firstresult.
  • Add a trivial changelog entry documenting the change.
testing/test_configuration.py
testing/test_hookcaller.py
changelog/705.trivial.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new HookSpec.opts property is read-only and no longer part of __slots__, so if existing code mutates spec.opts it will now fail; consider adding a setter that forwards to config (or explicitly confirming and documenting that opts is now a read-only deprecated alias) to avoid subtle breakage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `HookSpec.opts` property is read-only and no longer part of `__slots__`, so if existing code mutates `spec.opts` it will now fail; consider adding a setter that forwards to `config` (or explicitly confirming and documenting that `opts` is now a read-only deprecated alias) to avoid subtle breakage.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/markers-attach-config branch from 6238439 to e406f69 Compare July 24, 2026 16:38
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/configuration-objects branch from 65ee170 to 6993f10 Compare July 24, 2026 16:53
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/markers-attach-config branch from e406f69 to 5b654ff Compare July 24, 2026 16:54
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/configuration-objects branch from 6993f10 to 035b254 Compare August 12, 2026 10:50
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/markers-attach-config branch from 5b654ff to 1ac246f Compare August 12, 2026 10:50
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/configuration-objects branch from 035b254 to ad3a5a9 Compare August 12, 2026 10:57
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/markers-attach-config branch from 1ac246f to 4dc4e1f Compare August 12, 2026 10:57
Complete design step 03: markers already attach configuration objects
since step 02; this finishes the step by storing the spec configuration
as HookSpec.config (try-claude naming) with a deprecated .opts alias,
reading .config in HookCaller firstresult resolution, and covering
decoration-time historic+firstresult validation and configuration
attachment with tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant