Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FBT003 with Pydantic #10485

Closed
redb0 opened this issue Mar 20, 2024 · 3 comments · Fixed by #10531
Closed

FBT003 with Pydantic #10485

redb0 opened this issue Mar 20, 2024 · 3 comments · Fixed by #10531
Labels
configuration Related to settings and configuration rule Implementing or modifying a lint rule

Comments

@redb0
Copy link

redb0 commented Mar 20, 2024

Hello!

I use Ruff version 0.1.15 with flake8-boolean-trap. I am getting this error in the following example:

from pydantic import Field
from pydantic_settings import BaseSettings


class Settings(BaseSettings):

    foo: bool = Field(True, exclude=True)

Command ruff test.py --fix return

test.py:7:23: FBT003 Boolean positional value in function call

Pydantic allows you to explicitly specify the default parameter (foo: bool = Field(default=True, ...)). However, this stands out from the general code, where other values ​​are specified without it.

I’m not sure that it’s worth “strictly” filtering such cases. On the one hand, I can disable this check for certain files. I think it's not right to do this. Maybe it’s worth allowing the user to independently specify filtering rules, in addition to those initially specified as here https://github.com/astral-sh/ruff/blob/main/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs#L7?

I'd be glad to hear your opinion.

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Mar 20, 2024
@zanieb
Copy link
Member

zanieb commented Mar 20, 2024

Basically the same concept as #10356 (comment)

I think we should add a configurable list of allowed types / calls.

@zanieb zanieb added configuration Related to settings and configuration and removed needs-decision Awaiting a decision from a maintainer labels Mar 20, 2024
@redb0
Copy link
Author

redb0 commented Mar 20, 2024

@zanieb Yes, I also encountered several similar problems #4172, #4382, #6711 and other. I think a list of available names/calls would be the most flexible solution

@augustelalande
Copy link
Contributor

I will implement this

charliermarsh pushed a commit that referenced this issue Mar 30, 2024
…trap (#10531)

## Summary

Add a setting `extend-allowed-calls` to allow users to define their own
list of calls which allow boolean traps.

Resolves #10485.
Resolves #10356.

## Test Plan

Extended text fixture and added setting test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants