Coder Social home page Coder Social logo

bckohan / enum-properties Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 0.0 216 KB

Add properties and method specializations to Python enumeration values with a simple declarative syntax.

Home Page: https://enum-properties.readthedocs.io

License: MIT License

Python 100.00%
defines enum enums properties python python3

enum-properties's People

Contributors

bckohan avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

enum-properties's Issues

Add convenience property to decompose Flag enumeration values

Base python library does not expose a public interface to decompose a Flag enumeration into its activated flags. Provide a property that does this - may wrap enum internal code that does this so long as CI tests are sufficient to catch breaking changes in future.

Address python 3.11+ deprecation warnings.

/Users/bckohan/Development/enum-properties/enum_properties/init.py:370: DeprecationWarning: In 3.13 classes created inside an enum will not become a member. Use the member decorator to keep the current behavior.

Performance improvements

There are some deficiencies in how properties are stored and accessed on the member values. This access should be changed to direct attribute access instead of going through a member to value dictionary lookup. Will have to find a way to assign properties with None values to unlisted flag values.

Hash equivalency between values and enums is broken

Python Enums are hash equivalent to their values, so you can do things like this:

from enum import IntEnum

class MyEnum(IntEnum):
    VAL1 = 1
    VAL2 = 2
    VAL3 = 3

assert {1: '1', 2: '2', 3: '3'}[MyEnum.VAL2] == '2'  # this passes

However when using enum properties this does not work:

from enum import IntEnumProperties

class MyEnum(IntEnumProperties):
    VAL1 = 1
    VAL2 = 2
    VAL3 = 3

assert {1: '1', 2: '2', 3: '3'}[MyEnum.VAL2] == '2'  # this fails

Add static type hints.

The typing in this package is extremely dynamic so its unclear if the current state of static type checking in python is worth the trouble - but once it is it should be added.

Configurable behavior for matching none on symmetric fields

Symmetric fields that sometimes have none values should be able to switch off symmetrical mapping to None. Current behavior is to map the values if match on none, but a more reasonable default might be to turn off none mapping and require users to turn it back on.

For instance:

class MyEnum(EnumProperties, s('label', match_none=False)):
    
    VAL1 = 1, 'label'
    VAL2 = 2, None

MyEnum(None)  # raises value error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.