Skip to content

Autofix EM101 #9052

@kunaltyagi

Description

@kunaltyagi

EM101: Exception must not use a string literal, assign to variable first

This seems a simple enough to auto-fix given the example

current

    raise XYZ(<some-kind-of-string>)

autofix to:

    msg = <some-kind-of-string>
    raise XYZ(msg)
  1. if msg has been previously defined, we could still fail (with an unfixable message) (or try weird names for the variable like message, xyz_msg, xyz_message, error_msg, error_message, etc.)

Verified no autofix for:

  • ruff: ruff 0.1.7
  • python: 3.11
  • nothing relevant to em101 in pyproject.toml (except selecting "EM")

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