flake8-return icon indicating copy to clipboard operation
flake8-return copied to clipboard

Possible False Positive for R504

Open crimsonknave opened this issue 3 years ago • 1 comments

  • Date you used flake8-return: Oct 25th 2022
  • flake8-return version used, if any: 1.1.3
  • Python version, if any: 3.10.7
  • Operating System: Linux

Description

I have a fixture that creates a mock object, patches a library to return that mock object for a specific method and then returns the mock object so that assertions can be made on it. It seems quite clear that I am in fact using the variable, not sure why it's triggering the linting rule.

I was able to refactor the code to make the lint pass (the second example below), but that code is much less intuitive to me and messy.

What I Did

@pytest.fixture()
def example_mock_fails_linting(mocker):
    mock = mocker.MagicMock()
    mocker.patch("path.to.mocked.method.that.returns.an.object").return_value = mock
    return mock # R504 triggers for this line


@pytest.fixture()
def example_mock_lints_clean(mocker):
    example = mocker.patch("path.to.mocked.method.that.returns.an.object")
    example.return_value = mocker.MagicMock()
    return example.return_value # R504 doesn't trigger for this line

crimsonknave avatar Oct 25 '22 21:10 crimsonknave

Thank you for your issue! If you can try to fix this, I'm willing to consider a merge request.

afonasev avatar Oct 26 '22 09:10 afonasev