Skip to content

EM101 could support byte strings #18765

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

EM101 currently doesn't flag errors that have byte strings, despite them still causing a duplicate message playground

PS ~\Desktop\New_folder>Get-Content issue.py
raise RuntimeError(b"error message")  # no error
raise RuntimeError("error message")  # EM101
PS ~\Desktop\New_folder>uvx ruff check issue.py --select EM
issue.py:2:20: EM101 Exception must not use a string literal, assign to variable first
  |
1 | raise RuntimeError(b"error message")  # no error
2 | raise RuntimeError("error message")  # EM101
  |                    ^^^^^^^^^^^^^^^ EM101
  |
  = help: Assign to variable; remove string literal

Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
PS ~\Desktop\New_folder>py issue.py
Traceback (most recent call last):
  File "~\Desktop\New_folder\issue.py", line 1, in <module>
    raise RuntimeError(b"error message")  # no error
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: b'error message'

A github search for raise RuntimeError(b" gives a decent number of results, so this is not unheard of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions