← 返回首页
gh-102978: Fix mock.patch function signatures for class and staticmethod decorators by tomasr8 · Pull Request #103228 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-102978: Fix mock.patch function signatures for class and staticmethod decorators#103228

Merged
cjw296 merged 6 commits into
python:mainfrom
tomasr8:gh-102978
Apr 13, 2023
Merged

gh-102978: Fix mock.patch function signatures for class and staticmethod decorators#103228
cjw296 merged 6 commits into
python:mainfrom
tomasr8:gh-102978

Conversation

tomasr8 commented Apr 3, 2023
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Closes #102978

As reported in the original issue, unittest.mock.patch does not correctly extract function signatures from methods decorated with @classmethod and @staticmethod when patch is called with autospec=True.

This fix adds a special case to the extraction logic which uses the original decorated function via __func__ to get the correct signature.

I also updated the relevant tests.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unittest.mock.patch with autospec doesn't hold for classmethods nor staticmethods

6 participants

Footer

© 2026 GitHub, Inc.