Skip to content

Warn for deprecated hookimpl arguments with defaults - #743

Merged
bluetech merged 3 commits into
pytest-dev:mainfrom
feiiiiii5:fix-warn-defaulted-args
Sep 27, 2026
Merged

bluetech merged 3 commits into
pytest-dev:mainfrom
feiiiiii5:fix-warn-defaulted-args

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Summary

Make warn_on_impl_args inspect hook implementation parameters that have defaults as well as required parameters.

Motivation

HookImpl stores required parameters in argnames and defaulted parameters in kwargnames. The current warning check only scans argnames, so a plugin that keeps a deprecated argument working by giving it a default receives no deprecation warning. This contradicts the documented contract that any implementation requesting a configured deprecated argument triggers its warning.

Changes

  • Include hookimpl.kwargnames in the warning lookup.
  • Add a regression test covering a deprecated hook argument with a default.

This intentionally starts emitting warnings for the previously silent defaulted-argument case, which is the documented purpose of warn_on_impl_args.

Testing

  • Base origin/main with the new regression: failed because no warning was emitted.
  • uv run pytest: 202 passed.
  • uv run pre-commit run -a: all hooks passed.

A towncrier fragment will be added after the PR number is assigned.

@bluetech bluetech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for catching this

Comment thread changelog/743.bugfix.rst Outdated
@@ -0,0 +1 @@
Fixed ``warn_on_impl_args`` to warn when a hook implementation requests a deprecated argument with a default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't need a changelog since it hasn't been released yet (I'll remove it).

@bluetech
bluetech merged commit 6abdcf6 into pytest-dev:main Sep 27, 2026
19 of 20 checks passed
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.

2 participants