Skip to content

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

Open
@ntBre

Description

@ntBre

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions