Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Simple transition method overriding #65

Closed
kmmbvnr opened this issue Nov 12, 2014 · 2 comments
Closed

Simple transition method overriding #65

kmmbvnr opened this issue Nov 12, 2014 · 2 comments

Comments

@kmmbvnr
Copy link
Collaborator

kmmbvnr commented Nov 12, 2014

No need to repeat @transition decorator parameters again

https://github.com/viewflow/viewflow/blob/master/tests/unit/tests/test_fsm.py#L22

@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Nov 22, 2014

and even simpler http://repl.it/3qC/5

from functools import partial

def secret_decorator(func):
    def inner(self):
        print 'decorated'
        func(self)

    from functools import partial
    class Desc(object):
        def __call__(self): func(self)
        def __get__(self, instance): return partial(func, instance)

    inner.original = Desc()
    return inner


class Base(object):
    @secret_decorator
    def method(self):
        print('base')


class Child(Base):
    @secret_decorator
    def method(self):
        print('child')
        # bypass super/secret_decorator and directly call method impl
        super(Child, self).method.original()
 
base, child = Base(), Child()
 
base.method()
 
child.method()

@kmmbvnr kmmbvnr added the 3.0 label Oct 14, 2015
@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Dec 9, 2020

Implemented in the viewflow.fsm package

https://docs-next.viewflow.io/fsm/inheritance.html

@kmmbvnr kmmbvnr closed this as completed Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant