PyCQA/flake8-bugbear

B008: extend-immutable-calls does not work with imported function

オープン

#252 opened on 2022/04/04

 (5 件のコメント) (1 件のリアクション) (0 人の担当者)Python (116 件のフォーク)github user discovery
bugenhancementhelp wanted

Repository metrics

Stars
 (1,116 個のスター)
PR merge metrics
 (平均マージ 4h 17m) (30d で 3 merged PRs)

説明

I have small framework, which has Depends function simialr to fastapi feature. In my projects I want flake8-bubear to ignore only this funcion, but not any other function with same name. I've tried to set full link in flake config, but it does not work. I know that it is possible to always use full function name, but it looks dirty:

Example 1. Correct behavior - no B008 In config:

extend-immutable-calls=myapp.api.lambda_handler.depends.Depends

In code

import myapp.api.lambda_handler.depends

@app.handler
def get_data(
        session: Session = myapp.api.lambda_handler.depends.Depends(),
) -> HttpResponse[ListResponse[AA]]:

Example 2. Incorrect behavior - B008 In config:

extend-immutable-calls=myapp.api.lambda_handler.depends.Depends

In code

from myapp.api.lambda_handler.depends import Depends

@app.handler
def get_data(
        session: Session = Depends(),
) -> HttpResponse[ListResponse[AA]]:

Example 3. Incorrect behavior - no B008

extend-immutable-calls=Depends
from myapp.api.lambda_handler.depends import Depends

@app.handler
def get_data(
        session: Session = Depends(),
) -> HttpResponse[ListResponse[AA]]:
    ...

def Depends(): 
    return []

@app.handler
def put_data(
        session: Session = Depends(),
) -> HttpResponse[ListResponse[AA]]:

コントリビューターガイド