Skip to content
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

Merged
merged 1 commit into from Oct 7, 2018

Conversation

matllubos
Copy link
Collaborator

No description provided.

from collections import MutableSet, OrderedDict
from itertools import chain


ENUM_KEY_PATTERN = re.compile(r'^[a-zA-Z][a-zA-Z0-9_]*$')
Copy link
Collaborator Author

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}
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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__()
Copy link
Collaborator Author

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):
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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):
Copy link
Collaborator Author

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ů

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0007%) to 88.454% when pulling 37f10a8 on ImproveEnumStructures into 9d16ca8 on master.

@matllubos matllubos merged commit 87afbaf into master Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants