-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix FBT001 false negative with unions and optional #7501
Fix FBT001 false negative with unions and optional #7501
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FBT001 | 214 | 214 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+209 -0 violations, +0 -0 fixes in 41 projects)
apache/airflow (+84 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ airflow/callbacks/callback_requests.py:120:9: FBT001 Boolean-typed positional argument in function definition + airflow/callbacks/callback_requests.py:80:9: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_external_python.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_python.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_virtualenv.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/external_python.py:38:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/python.py:63:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/python_virtualenv.py:37:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/short_circuit.py:37:5: FBT001 Boolean-typed positional argument in function definition + airflow/lineage/entities.py:73:21: FBT001 Boolean-typed positional argument in function definition + airflow/models/baseoperator.py:1482:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:2869:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:3836:5: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:460:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:101:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:98:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:99:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagrun.py:212:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagrun.py:379:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/taskinstance.py:2599:9: FBT001 Boolean-typed positional argument in function definition ... 64 additional changes omitted for project
bokeh/bokeh (+5 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ src/bokeh/embed/util.py:183:65: FBT001 Boolean-typed positional argument in function definition + src/bokeh/server/tornado.py:608:25: FBT001 Boolean-typed positional argument in function definition + src/bokeh/settings.py:167:18: FBT001 Boolean-typed positional argument in function definition + src/bokeh/util/token.py:207:32: FBT001 Boolean-typed positional argument in function definition + src/typings/selenium/webdriver/firefox/options.pyi:3:41: FBT001 Boolean-typed positional argument in function definition
zulip/zulip (+120 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ analytics/lib/counts.py:301:5: FBT001 Boolean-typed positional argument in function definition + analytics/views/support.py:169:5: FBT001 Boolean-typed positional argument in function definition + corporate/tests/test_stripe.py:448:9: FBT001 Boolean-typed positional argument in function definition + zerver/actions/create_user.py:413:5: FBT001 Boolean-typed positional argument in function definition + zerver/actions/user_settings.py:400:5: FBT001 Boolean-typed positional argument in function definition + zerver/actions/user_status.py:11:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/create_user.py:159:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/create_user.py:164:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/event_schema.py:1572:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/export.py:1931:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/export.py:2392:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/management.py:120:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1728:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1753:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1775:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/notification_data.py:266:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/streams.py:94:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_classes.py:1345:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_classes.py:825:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_runner.py:188:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/webhooks/git.py:98:5: FBT001 Boolean-typed positional argument in function definition + zerver/tests/test_realm_export.py:124:13: FBT001 Boolean-typed positional argument in function definition + zerver/tornado/django_api.py:41:9: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:21:32: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:46:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:50:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/realm.py:101:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/realm.py:112:5: FBT001 Boolean-typed positional argument in function definition ... 92 additional changes omitted for project
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FBT001 | 209 | 209 | 0 | 0 | 0 |
This could introduce a lot of new positives. |
6465010
to
47fc41d
Compare
Expr::Constant(ast::ExprConstant { | ||
value: Constant::Str(ast::StringConstant { value, .. }), | ||
.. | ||
}) => value == "bool", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #8064 merged, you'll need to update this to use Expr::StringLiteral
instead:
Expr::Constant(ast::ExprConstant { | |
value: Constant::Str(ast::StringConstant { value, .. }), | |
.. | |
}) => value == "bool", | |
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => value == "bool", |
47fc41d
to
d755162
Compare
d755162
to
e356126
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FBT001 | 214 | 214 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+209 -0 violations, +0 -0 fixes in 41 projects)
apache/airflow (+84 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ airflow/callbacks/callback_requests.py:120:9: FBT001 Boolean-typed positional argument in function definition + airflow/callbacks/callback_requests.py:80:9: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_external_python.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_python.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/branch_virtualenv.py:36:46: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/external_python.py:38:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/python.py:63:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/python_virtualenv.py:37:5: FBT001 Boolean-typed positional argument in function definition + airflow/decorators/short_circuit.py:37:5: FBT001 Boolean-typed positional argument in function definition + airflow/lineage/entities.py:73:21: FBT001 Boolean-typed positional argument in function definition + airflow/models/baseoperator.py:1482:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:2869:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:3836:5: FBT001 Boolean-typed positional argument in function definition + airflow/models/dag.py:460:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:101:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:98:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagbag.py:99:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagrun.py:212:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/dagrun.py:379:9: FBT001 Boolean-typed positional argument in function definition + airflow/models/taskinstance.py:2599:9: FBT001 Boolean-typed positional argument in function definition ... 64 additional changes omitted for project
bokeh/bokeh (+5 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ src/bokeh/embed/util.py:183:65: FBT001 Boolean-typed positional argument in function definition + src/bokeh/server/tornado.py:608:25: FBT001 Boolean-typed positional argument in function definition + src/bokeh/settings.py:167:18: FBT001 Boolean-typed positional argument in function definition + src/bokeh/util/token.py:207:32: FBT001 Boolean-typed positional argument in function definition + src/typings/selenium/webdriver/firefox/options.pyi:3:41: FBT001 Boolean-typed positional argument in function definition
zulip/zulip (+120 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --select ALL --preview
+ analytics/lib/counts.py:301:5: FBT001 Boolean-typed positional argument in function definition + analytics/views/support.py:169:5: FBT001 Boolean-typed positional argument in function definition + corporate/tests/test_stripe.py:448:9: FBT001 Boolean-typed positional argument in function definition + zerver/actions/create_user.py:413:5: FBT001 Boolean-typed positional argument in function definition + zerver/actions/user_settings.py:400:5: FBT001 Boolean-typed positional argument in function definition + zerver/actions/user_status.py:11:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/create_user.py:159:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/create_user.py:164:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/event_schema.py:1572:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/export.py:1931:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/export.py:2392:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/management.py:120:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1728:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1753:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/message.py:1775:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/notification_data.py:266:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/streams.py:94:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_classes.py:1345:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_classes.py:825:9: FBT001 Boolean-typed positional argument in function definition + zerver/lib/test_runner.py:188:5: FBT001 Boolean-typed positional argument in function definition + zerver/lib/webhooks/git.py:98:5: FBT001 Boolean-typed positional argument in function definition + zerver/tests/test_realm_export.py:124:13: FBT001 Boolean-typed positional argument in function definition + zerver/tornado/django_api.py:41:9: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:21:32: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:46:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/events_register.py:50:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/realm.py:101:5: FBT001 Boolean-typed positional argument in function definition + zerver/views/realm.py:112:5: FBT001 Boolean-typed positional argument in function definition ... 92 additional changes omitted for project
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FBT001 | 209 | 209 | 0 | 0 | 0 |
How should I proceed to make this behavior change only for the preview mode? |
@JonathanPlasse - I think you could change |
} | ||
} | ||
_ => false, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhruvmanila - Is it possible to use TypingTarget
for this?
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FBT001 | 214 | 214 | 0 | 0 | 0 |
Summary
bool | None
#7487In the spirit of
flake8-boolean-trap
, any positional argument that can accept a boolean should raiseFBT001
.Raise
FBT001
for all annotations that accept booleans (e.g.Optional[bool]
,Union[int, bool]
).Test Plan
Add a fixture, with an annotation using
|
,Optional
, andUnion
, and containing a boolean.