jamescooke/flake8-aaa

Marking `# act` on a multi-line function call is unintuitive

jamescooke opened this issue · 0 comments

Current behaviour

Given a test where we want to call a validator and assert that no errors were raised (and the validator is -> None so there's no output to check either), we have:

def test() -> None:
    validate_row(
        {"total_number_of_users": "1", "number_of_new_users": "0"},
        ["total_number_of_users", "number_of_new_users"],
    )  # act

But Flake8-AAA can not find this Act block:

------+------------------------------------------------------------------------
 7 DEF|def test() -> None:                                                                               
       ^ AAA01 no Act block found in test                                                                
 8 ???|    validate_row(
 9 ???|        {"total_number_of_users": "1", "number_of_new_users": "0"},     
10 ???|        ["total_number_of_users", "number_of_new_users"],
11 ???|    )  # act                                 
------+------------------------------------------------------------------------
    1 | ERROR

Instead the # act annotation has to be put "inside" the function's args:

def test() -> None:
    validate_row(  # act
        {"total_number_of_users": "1", "number_of_new_users": "0"},
        ["total_number_of_users", "number_of_new_users"],
    )

Which gives:

------+------------------------------------------------------------------------    
 7 DEF|def test() -> None:                                                                               
 8 ACT|    validate_row(  # act
 9 ACT|        {"total_number_of_users": "1", "number_of_new_users": "0"},     
10 ACT|        ["total_number_of_users", "number_of_new_users"],
11 ACT|    )                             
------+------------------------------------------------------------------------
    0 | ERRORS

Expected behaviour

Marking the line with closing parenthesis should work ) # act. It looks cleaner. It also means that as args / kwargs are stuffed inside an already-annotated function call and the single line is reformatted to be multi-line, Flake8-AAA won't break.