Skip to content

pyupgrade rule: upgrading str, Enum to StrEnum #9569

@jamesbraza

Description

@jamesbraza

Since Python 3.11 there are now StrEnum and IntEnum:

from enum import Enum, IntEnum, StrEnum

class Foo(str, Enum):  ...  # Python<3.11
class Foo(StrEnum):  ...  # Python>=3.11

class Bar(int, Enum): ...  # Python<3.11
class Bar(IntEnum): ...  # Python>=3.11

pyupgrade can be used to suggest this change.

However, this request was rejected in pyupgrade itself here: asottile/pyupgrade#779. Apparently they're not identical in behavior. Luckily, ruff has a concept of safe vs unsafe, so I think ruff can actually implement this rule.

The request here is for ruff to suggest this upgrade as an unsafe fix, ideally with autofix support.

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomersruleImplementing 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