mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00

## Summary Implementation for one of the rules in https://github.com/astral-sh/ruff/issues/1348 Refurb only deals only with classes with a single base, however the rule is valid for any base. (`str, Enum` is common prior to `StrEnum`) ## Test Plan `cargo test` --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
42 lines
806 B
Python
42 lines
806 B
Python
# setup
|
|
from enum import Enum, EnumMeta
|
|
from collections import UserList as UL
|
|
|
|
class SetOnceMappingMixin:
|
|
__slots__ = ()
|
|
def __setitem__(self, key, value):
|
|
if key in self:
|
|
raise KeyError(str(key) + ' already set')
|
|
return super().__setitem__(key, value)
|
|
|
|
|
|
class CaseInsensitiveEnumMeta(EnumMeta):
|
|
pass
|
|
|
|
# positives
|
|
class D(dict):
|
|
pass
|
|
|
|
class L(list):
|
|
pass
|
|
|
|
class S(str):
|
|
pass
|
|
|
|
# currently not detected
|
|
class SetOnceDict(SetOnceMappingMixin, dict):
|
|
pass
|
|
|
|
# negatives
|
|
class C:
|
|
pass
|
|
|
|
class I(int):
|
|
pass
|
|
|
|
class ActivityState(str, Enum, metaclass=CaseInsensitiveEnumMeta):
|
|
"""Activity state. This is an optional property and if not provided, the state will be Active by
|
|
default.
|
|
"""
|
|
ACTIVE = "Active"
|
|
INACTIVE = "Inactive"
|