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

@delegated decorator should define methods on a decorated class. #77

Closed
proofit404 opened this issue Jul 10, 2020 · 0 comments · Fixed by #230
Closed

@delegated decorator should define methods on a decorated class. #77

proofit404 opened this issue Jul 10, 2020 · 0 comments · Fixed by #230

Comments

@proofit404
Copy link
Owner

proofit404 commented Jul 10, 2020

So it will look exactly like the source object.

Due to the limitation introduced in #222 we need to rethink an easy way to adjust behavior of a single method with as little code as inheritance required.

from generics import private, delegated


@private
class User:
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f'Hello, {self.name}')

    def say(self):
        print(f'Hi, {self.name})

@delegated(User)
class SuperUser:
    def __init__(self, user):
        self.user = user

    def greet(self):
        print('* ', end='')
        self.user.greet()

SuperUser(User('Kate')).greet() # => * Hello, Kate
SuperUser(User('Kate')).say() # => Hi, Kate 

As you can see, method say works as intended on SuperUser class where it was not defined.

proofit404 added a commit that referenced this issue Jun 2, 2022
proofit404 added a commit that referenced this issue Jun 2, 2022
proofit404 added a commit that referenced this issue Jul 9, 2022
proofit404 added a commit that referenced this issue Jul 9, 2022
proofit404 added a commit that referenced this issue Jul 13, 2022
proofit404 added a commit that referenced this issue Jul 13, 2022
github-actions bot pushed a commit that referenced this issue Jul 13, 2022
# 3.6.0 (2022-07-13)

### Features

* implement [@delegated](https://github.com/delegated) decorator [#77](#77) 916fd1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant