Skip to main content

backports.strenum

A backport of (copy and paste from) python 3.11’s StrEnum class for >=3.8.6:

See the design discussion, and Ethan Furman’s first and second PR with this implementation.

A slightly different implementation would likely be compatible with lower python versions; PRs are welcome if they pass the test suite. The existing (reference) implementation should still be the one used on supported versions.

Install with pip install backports.strenum, and use with:

import sys

if sys.version_info >= (3, 11):
    from enum import StrEnum
else:
    from backports.strenum import StrEnum

class MyStrEnum(StrEnum):
    POTATO = "potato"
    ORANGE = "orange"
    SPADE = "spade"

MyStrEnum.POTATO == "potato"  # True
MyStrEnum.ORANGE.upper() == "ORANGE"  # True
str(MyStrEnum.SPADE) == "spade"  # True

Gotchas

A number of behaviours relating to the treatment of enum classes as containers of their members (e.g. iterating and containment checks) will be changing in python 3.12.

This package intends only to allow pre-3.11 users to get 3.11-like behaviour; after that, stick with the standard library.


These are the docs provided with python 3.11:

class enum.StrEnum

StrEnum is the same as Enum, but its members are also strings and can be used in most of the same places that a string can be used. The result of any string operation performed on or with a StrEnum member is not part of the enumeration.

Metadata

Release files for backports.strenum 1.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backports.strenum 1.2.4
File Size Uploaded Provenance Actions
backports.strenum-1.2.4.tar.gz 10.7 kB Without provenance Details for backports.strenum-1.2.4.tar.gz

Release files / backports.strenum-1.2.4.tar.gz

Download URL backports.strenum-1.2.4.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
87b67fd1413af3ce959b565d84ddef99776cdd97a62e2fd2d0550cdacc210dee
BLAKE2b-256 checksum
How to use checksums
3382ca6bdbbfad48a15d88aab7e3aae3b2549ad089c36527a11bdf04d604613c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Security for backports.strenum 1.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page