hearsaycorp / richenum Goto Github PK
View Code? Open in Web Editor NEWA powerful enum library for Python.
Home Page: http://engineering.hearsaysocial.com/2013/09/16/enums-in-python/
License: MIT License
A powerful enum library for Python.
Home Page: http://engineering.hearsaysocial.com/2013/09/16/enums-in-python/
License: MIT License
Features:
RichEnumValue
RichEnumValue
RichEnum
metaclass enforces that aliases are unique across all RichEnumValue
s in the given RichEnum
RichEnum
s@rbm added a custom exception class for bad lookups, which I think is great. The problem is that it doesn't currently behave as a built-in LookupError
, though the error message printed makes it look like it does.
If you change the test on line 76 of test_rich_enums.py
to be:
with self.assertRaises(LookupError):
instead of just using the custom class type (EnumLookupError
), you get an error raised in the test:
======================================================================
ERROR: test_generic_lookup (tests.richenum.test_rich_enums.RichEnumTestSuite)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jeremiahlee/projects/richenum/tests/richenum/test_rich_enums.py", line 77, in test_generic_lookup
Vegetable.lookup('flavor', 'yum')
File "/Users/jeremiahlee/projects/richenum/src/richenum/enums.py", line 284, in lookup
% (field, value, cls)
LookupError: Could not find member matching flavor = yum in enum <class 'tests.richenum.test_rich_enums.Vegetable'>
This is throwing something that has a __name__
of LookupError, but isn't actually the built-in LookupError
, which I think is confusing to users of the library (e.g., me). I know that we could also catch Vegetable.LookupError
(which isn't obvious from the error message above) but I think it also makes sense to allow a plain LookupError
to be caught.
PR forthcoming.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.