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

Consider adding a fix for pytest-raises-ambiguous-pattern (RUF043) #16690

Open
ntBre opened this issue Mar 12, 2025 · 0 comments
Open

Consider adding a fix for pytest-raises-ambiguous-pattern (RUF043) #16690

ntBre opened this issue Mar 12, 2025 · 0 comments
Labels
fixes Related to suggested fixes for violations

Comments

@ntBre
Copy link
Contributor

ntBre commented Mar 12, 2025

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)

Originally posted by @MichaReiser in #16657 (review)

@ntBre ntBre added the fixes Related to suggested fixes for violations label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations
Projects
None yet
Development

No branches or pull requests

1 participant