Skip to content

[ruff] Stabilize pytest-raises-ambiguous-pattern (RUF043) #16657

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

Closed
wants to merge 1 commit into from

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Mar 12, 2025

Summary

Stabilizes RUF043 and moves its test to the right place. The docs look good.

Test Plan

0 closed or open issues. 1 follow-up PR to fix typos in the test documentation and 1 bug fix to treat ) as a regex meta-character on 2025-01-07.

This can be a pretty noisy rule (+503 violations in the initial PR), so we'll see how the ecosystem check looks now. I'm happy to hold off stabilizing if we think it's too noisy, just wanted to open the PR just in case.

Summary
--

Stabilizes RUF043 and moves its test to the right place. The docs look good.

Test Plan
--

0 closed or open issues. 1 follow-up PR to fix typos in the test documentation
and 1 bug fix to treat `)` as a regex meta-character on 2025-01-01.

This can be a pretty noisy rule (+503 violations in the initial PR), so we'll
see how the ecosystem check looks now.
@ntBre ntBre added the rule Implementing or modifying a lint rule label Mar 12, 2025
@ntBre ntBre added this to the v0.10 milestone Mar 12, 2025
Copy link

codspeed-hq bot commented Mar 12, 2025

CodSpeed Performance Report

Merging #16657 will degrade performances by 10.81%

Comparing brent/ruf043-0.10 (4175c38) with micha/ruff-0.10 (b8f1284)

Summary

❌ 1 regressions
✅ 31 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
red_knot_check_file[incremental] 4.9 ms 5.5 ms -10.81%

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+438 -0 violations, +0 -0 fixes in 14 projects; 41 projects unchanged)

DisnakeDev/disnake (+14 -0 violations, +0 -0 fixes)

+ tests/test_embeds.py:353:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:359:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:365:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:371:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:393:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:400:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:406:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_embeds.py:412:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_flags.py:163:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_flags.py:167:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
... 4 additional changes omitted for project

RasaHQ/rasa (+10 -0 violations, +0 -0 fixes)

+ tests/core/test_migrate.py:1066:30: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/core/test_migrate.py:1116:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/core/test_migrate.py:680:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/core/test_migrate.py:720:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/core/test_migrate.py:877:30: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/engine/test_validation.py:146:62: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/engine/test_validation.py:352:47: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/engine/test_validation.py:390:47: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/engine/test_validation.py:907:47: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/graph_components/validators/test_default_recipe_validator.py:462:54: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

apache/airflow (+107 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ kubernetes_tests/test_kubernetes_pod_operator.py:648:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ kubernetes_tests/test_kubernetes_pod_operator.py:688:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/auth_manager/avp/test_facade.py:192:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/auth_manager/avp/test_facade.py:235:37: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/auth_manager/avp/test_facade.py:277:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py:856:46: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py:877:46: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_comprehend.py:131:37: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_datasync.py:129:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:1391:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:160:17: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py:97:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
... 95 additional changes omitted for project

apache/superset (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ tests/integration_tests/db_engine_specs/hive_tests.py:256:19: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

bokeh/bokeh (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ tests/unit/bokeh/core/test_properties.py:395:48: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/unit/bokeh/core/test_properties.py:398:48: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/unit/bokeh/core/test_properties.py:401:48: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

ibis-project/ibis (+20 -0 violations, +0 -0 fixes)

+ ibis/backends/clickhouse/tests/test_client.py:424:40: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/flink/tests/test_ddl.py:141:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/impala/tests/test_exprs.py:593:48: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/pyspark/tests/test_udf.py:72:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/tests/test_client.py:349:34: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/tests/test_generic.py:455:34: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/tests/test_generic.py:460:34: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/tests/test_vectorized_udf.py:358:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/backends/tests/test_vectorized_udf.py:479:41: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ ibis/common/tests/test_annotations.py:251:32: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
... 10 additional changes omitted for project

pandas-dev/pandas (+177 -0 violations, +0 -0 fixes)

+ pandas/tests/apply/test_numba.py:120:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/apply/test_numba.py:126:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arithmetic/test_datetime64.py:1857:34: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/boolean/test_construction.py:189:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/boolean/test_construction.py:192:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/boolean/test_construction.py:30:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/boolean/test_construction.py:33:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/categorical/test_analytics.py:125:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/interval/test_overlaps.py:66:55: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/sparse/test_accessor.py:247:30: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/sparse/test_accessor.py:96:50: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/string_/test_string.py:299:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/string_/test_string.py:765:41: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/test_array.py:518:26: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/arrays/test_datetimelike.py:504:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/computation/test_eval.py:1871:41: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/config/test_config.py:273:48: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/dtypes/cast/test_construct_object_arr.py:19:41: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/dtypes/test_common.py:871:43: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ pandas/tests/dtypes/test_dtypes.py:388:45: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
... 157 additional changes omitted for project

pypa/build (+3 -0 violations, +0 -0 fixes)

+ tests/test_env.py:66:44: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_projectbuilder.py:464:52: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/test_util.py:35:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

python-poetry/poetry (+1 -0 violations, +0 -0 fixes)

+ tests/packages/test_locker.py:744:44: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

reflex-dev/reflex (+3 -0 violations, +0 -0 fixes)

+ tests/units/components/core/test_match.py:206:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/units/components/core/test_match.py:236:15: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
+ tests/units/components/core/test_match.py:311:42: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF043 438 438 0 0 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
Copy link
Contributor Author

ntBre commented Mar 12, 2025

These all look like true positives and almost all with . as the meta-character. There are many slightly incorrect cases matching sentences (This is a sentence ending with period.) or matching versions (Python 3.10) or object fields (object.field is invalid).

I'm not totally sure if the number of hits actually decreased or if the truncation is just different. airflow is down 7 violations but ibis and pandas are +1 each.

@ntBre ntBre mentioned this pull request Mar 12, 2025
2 tasks
@MichaReiser
Copy link
Member

I'm not totally sure if the number of hits actually decreased or if the truncation is just different. airflow is down 7 violations but ibis and pandas are +1 each.

Do you mean compared to the initial PR? It's possible that some repositories use preview mode and have fixed the violations in their code.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certainly a more noisy rule and it's unfortunate we can't provide an auto fix (because Ruff can't know what the desired behavior is). But I think it's fine to stabilize

Unless we want to add a heuristic for the auto fix. E.g.:

  • A string ending with . is probably a sentence -> escape it
  • A string with a sequence of metacharacters (e.g. .* or .+) is probably a regex -> make it raw. We can limit it to only support some specific patterns.

The first fix would have to be unsafe because it does change the program's semantics. The second one could be safe but I think it's still best to make user explicitly opt-in. We could document the heuristics in the rule and having a fix could reduce the churn for users.

I'd postpone the promotion to stable if the suggested fix does sound reasonable (CC: @AlexWaygood)

@ntBre
Copy link
Contributor Author

ntBre commented Mar 12, 2025

I'm going to close this for now and open an issue with Micha's fix idea. The rule is a bit newer than most of the other stabilizations anyway.

I'm not opposed to reopening and merging it for v0.10, however. Just don't let me forget to add it back to the blog post!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants