Skip to content

PLR2004 does not care if magic value in comparison is a major version number against sys.implementation.version #25588

Closed

Description

@jonathandung

Summary

When reporting astral-sh/ty#3640, I noticed ruff emitted PLR2004 when I checked sys.implementation.version[0] against a number like 3. It would be unreasonable to require assigning 3 to a name such as PY3 before using it. The YTT rules do not concern this usage, so I think it is just PLR2004 that may need to be changed.

Playground

Version

ruff 0.15.15 (db5aa0a 2026-05-28)

Activity

  1. ntBre commented on Jun 3, 2026

    @ntBre
    Contributor

    I can certainly see your point, but I'm not sure we should start adding exceptions like this to the rule. I think it's fine to use a noqa here or add 3 to the configuration option once #18961 lands.

  2. added
    questionAn issue asking for support or clarification
    on Jun 3, 2026
  3. MichaReiser commented on Jun 3, 2026

    @MichaReiser
    Member

    Ruff has the same issue with sys.version. I'd be fine adding an exception for sys.version and maybe sys.implementation.version, if it's not too hard

  4. jonathandung commented on Jun 3, 2026

    @jonathandung
    ContributorAuthor

    The allow_magic_values config option seems promising.

  5. added
    ruleImplementing or modifying a lint rule
    and removed
    questionAn issue asking for support or clarification
    on Jun 3, 2026
  6. added a commit that references this issue on Jun 10, 2026
    7fbef67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing 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