I have the following code, which processes a POST request via fastapi. However, flake8 keeps throwing the B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time error.
@app.post("/predict", status_code=200)
def predict(
page_no: int = Form(...), dimensions: list = Form(...), image: UploadFile = File(...)
) -> Dict[str, int]:
Is there a way to fix these warnings, or work around them?
One solution is to to update your flake8 configuration (e.g. in your setup.cfg file) to ignore this rule for the Depends(...) usage like this:
extend-immutable-calls = Depends, fastapi.Depends, fastapi.params.Depends
As of Dec 2022, you have to list the names manually, as the flake8-bugbear plugin doesn't know about the actual types (it's an AST parser), there is an open issue about it.
See more:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With