Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
ordered_enum is a small library for adding (total) orderings to enum.Enum
s.
It provides two ordering behaviors:
ordered_enum.OrderedEnum
: total ordering by definitionordered_enum.ValueOrderedEnum
: "total" ordering by member valuesordered_enum requires Python 3.7 or newer.
pip3 install ordered_enum
To use ordered_enum, just use OrderedEnum
or ValueOrderedEnum
as your parent class:
from ordered_enum import OrderedEnum
class State(OrderedEnum):
Disabled = 4
Loaded = 3
Waiting = 2
Running = 1
Dead = 0
assert(State.Disabled < State.Loaded)
assert(sorted([State.Dead, State.Waiting]) == [State.Waiting, State.Dead])
OrderedEnum
doesn't require @enum.unique
(or unique values at all); it uses the order of
definition to impose an ordering between members.
If you'd like to impose an ordering based on member values, you can use ValueOrderedEnum
instead:
import enum
from ordered_enum import ValueOrderedEnum
@enum.unique
class State(ValueOrderedEnum):
Disabled = 4
Loaded = 3
Waiting = 2
Running = 1
Dead = 0
assert(State.Disabled > State.Loaded)
assert(sorted([State.Waiting, State.Dead]) == [State.Dead, State.Waiting])
ValueOrderedEnum
does require unique values, which can be enforced via @enum.unique
.
Failing to make a ValueOrderedEnum
's values unique will result in a silently broken ordering.
As mentioned above, ordered_enum.OrderedEnum
provides an ordering of enum values based on their order
of definition in the class. This means that:
Therefore, you should either not depend on a specific ordering or ensure that your order of definition is the order you'd like.
FAQs
A small library for adding total orderings to enums
We found that ordered-enum demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.