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

implementations as attribute into the instance #341

Open
loic001 opened this issue Jan 30, 2021 · 1 comment
Open

implementations as attribute into the instance #341

loic001 opened this issue Jan 30, 2021 · 1 comment

Comments

@loic001
Copy link

loic001 commented Jan 30, 2021

First of all, congratulations for this work!

As mentioned here "implementations are registered as attribute into the instance".

But it doesn't seem to work... It seems that the retrieve_document function is made for this but I would have preferred an instance.MyImplementedDocument approach. I don't want to use the retrieve_document function because it's just too verbose.

Can you shed some light on this?

Note that I don't want to use register as a decorator, to decouple the documents from the backend choice. For the moment I have only found this as a troubleshooting solution:

class MyMotorAsyncIOInstance(MotorAsyncIOInstance):
    def __getattr__(self, attr):
        return self.retrieve_document(attr)

But there are also embedded documents or mixins to manage so I'm not too happy with this approach. Then maybe it would be better to do that?

class MyMotorAsyncIOInstance(MotorAsyncIOInstance):
    def register(self, template):
        implementation = super(MyMotorAsyncIOInstance, self).register(template)
        setattr(self, template.__name__, implementation)
        return implementation

Thanks for your help!

@lafrech
Copy link
Collaborator

lafrech commented Apr 13, 2021

Indeed, looks like the docstring is outdated. The note below doesn't mention Mixin.

I think I removed this because

  • I didn't see a use case
  • There could be name clashes if a Doc and an Embedded doc have the same name that could catch the user by surprise.

Do you really have a use case for this?

If you use instance.Doc somewhere, why not just import Doc?

At least, the docstring should be fixed, so thanks for reporting.

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

No branches or pull requests

2 participants