-
Notifications
You must be signed in to change notification settings - Fork 528
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
Generate predicate methods in lowercase #385
Comments
Hi @artofhuman,
currently, I would say thats some quite specific (yet reasonable) use case that does not justify the increase in code complexity and yet another parameter in For now: import enum
from transitions import Machine
class States(enum.Enum):
ERROR = 0
RED = 1
YELLOW = 2
GREEN = 3
class LowerCaseMachine(Machine):
def _checked_assignment(self, model, name, func):
super(LowerCaseMachine, self)._checked_assignment(model, name.lower(), func)
m = LowerCaseMachine(states=States, initial=States.RED)
assert m.is_red() Alternatively, if only state-related functions should be changed, one could override class LowerCaseMachine(Machine):
def _add_model_to_state(self, state, model):
# change state.name to state.name.lower() here ...
self._checked_assignment(model, 'is_%s' % state.name.lower(), partial(self.is_state, state.value, model))
for callback in self.state_cls.dynamic_methods:
# ... and maybe here
method = "{0}_{1}".format(callback, state.name.lower())
if hasattr(model, method) and inspect.ismethod(getattr(model, method)) and \
method not in getattr(state, callback):
state.add_callback(callback[3:], method) |
Closing this since there hasnt been new input for more than 14 days. Feel free to comment if there is more to add. I will reopen the issue if necessary. |
Hi, @aleneum.
What do you think about the additional option for generating predicate methods in lowercase?
For example if we use enums usually we add enum values in uppercase like:
And machine generate predicate methods like:
m.is_RED()
where state name part in upperacese.It dont allows switching from strings to enums without rewrite codebase.
For example
if we have old machine
m = Machine(states=['error', 'red'], transitions=transitions, initial='red')
and want to switch to enums we should rewrite predicates from
.is_error()
to.is_ERROR()
In this case, I propose to add the option to machine
auto_lowercase=True
or same analog.I can prepare PR for this. WDYT?
The text was updated successfully, but these errors were encountered: