[pygrep_hooks] Add AsyncMock methods to invalid-mock-access (PGH005) by robsdedude · Pull Request #18547 · astral-sh/ruff (original) (raw)

Conversation

@robsdedude

Summary

This PR expands PGH005 to also check for AsyncMock methods in the same vein. E.g., currently assert mock.not_called is linted. This PR adds the corresponding async assertions assert mock.not_awaited().

@robsdedude

robsdedude

| "called_with"
| "has_calls"
| "not_called"
| "awaited"

Choose a reason for hiding this comment

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

N.B., the sync equivalent called is not in this list. That is because (sync) Mocks have a boolean attribute called. However, AsyncMocks do not have an attribute awaited. Therefore, assert mock.awaited is likely a mistake and was meant to be mock.assert_awaited().

robsdedude

@github-actions

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre added the rule

Implementing or modifying a lint rule

label

Jun 9, 2025

@robsdedude

ntBre

Choose a reason for hiding this comment

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

Makes sense, thanks! Just one tiny suggestion to include the URL for the PR on the preview function.

@robsdedude @ntBre

Co-authored-by: Brent Westbrook 36778786+ntBre@users.noreply.github.com

@robsdedude

ntBre

@ntBre ntBre changed the title[pygrep_hooks] add AsyncMock methods to invalid-mock-access (PGH005) [pygrep_hooks] Add AsyncMock methods to invalid-mock-access (PGH005)

Jun 24, 2025

@robsdedude robsdedude deleted the feat/pgh005-add-async-mock-methods branch

June 24, 2025 21:32

dylwil3 added a commit that referenced this pull request

Sep 8, 2025

@dylwil3

…access (PGH005`) (#20272)

Introduced in #18547. Removed gating, updated tests. Not documented so documentation is the same.

ntBre pushed a commit that referenced this pull request

Sep 8, 2025

@dylwil3 @ntBre

…access (PGH005`) (#20272)

Introduced in #18547. Removed gating, updated tests. Not documented so documentation is the same.

ntBre pushed a commit that referenced this pull request

Sep 10, 2025

@dylwil3 @ntBre

…access (PGH005`) (#20272)

Introduced in #18547. Removed gating, updated tests. Not documented so documentation is the same.

ntBre pushed a commit that referenced this pull request

Sep 10, 2025

@dylwil3 @ntBre

…access (PGH005`) (#20272)

Introduced in #18547. Removed gating, updated tests. Not documented so documentation is the same.

ntBre pushed a commit that referenced this pull request

Sep 10, 2025

@dylwil3 @ntBre

…access (PGH005`) (#20272)

Introduced in #18547. Removed gating, updated tests. Not documented so documentation is the same.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

Labels

preview

Related to preview mode features

rule

Implementing or modifying a lint rule

2 participants

@robsdedude @ntBre