New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaned enum structures and added new features #61
Conversation
from collections import MutableSet, OrderedDict | ||
from itertools import chain | ||
|
||
|
||
ENUM_KEY_PATTERN = re.compile(r'^[a-zA-Z][a-zA-Z0-9_]*$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omezil jsem názvy klíčů enumů
raise ValueError('Enum key "{}" has invalid format'.format(k)) | ||
|
||
self._container = OrderedDict(items) | ||
self._reverse_container = {item[1]: item[0] for item in items} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
původně se iterovalo v _container, což může být časově trošku horší, tak si připravuji i reverzní dict
@@ -23,127 +35,86 @@ def __deepcopy__(self, *args, **kwargs): | |||
# Enum is immutable | |||
return self | |||
|
|||
def __contains__(self, item): | |||
return item in self._reverse_container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
na enumy funguje operátor in
return item in self._reverse_container | ||
|
||
def __iter__(self): | ||
return self._container.values().__iter__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enumy jsou iterable, není nutné volat all, ale all vytvoří tuple namísto generátoru, což se může hodit
|
||
|
||
class NumEnum(AbstractEnum): | ||
class NumEnum(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num enum je nyní jen speciální typ enumu, který kontroluje, že hodnoty jsou čísla a umí hondnoty auto generovat (jinak vlastně není rozdíl)
def choices(self): | ||
return self._get_choices() | ||
super().__init__(*enum_items) | ||
self.choices = tuple( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nyní jsou choices ve vlastní struktuře, dříve se prasila základní struktura enumu a blbě se s tím pracovalo, navíc nám správně nefungovala dědičnost enumů
@@ -91,11 +91,11 @@ SmartModel | |||
|
|||
List of defined pre or post save dispatchers. More obout it will find _dispatchers | |||
|
|||
.. property:: has_changed | |||
.. attribute:: has_changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property neexistuje.
@@ -33,18 +33,75 @@ Enums | |||
|
|||
Base enumeration class with controlled ``__getattr__``. | |||
|
|||
.. attribute:: chamber.utils.datastructures.AbstractEnum.all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
troška té dokumentace s příklady
|
||
|
||
class DatastructuresTestCase(TestCase): | ||
|
||
def test_enum(self): | ||
def test_enum_should_contain_only_defined_values(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trošku těch testů
af351f7
to
37f10a8
Compare
No description provided.