Dependency Proxy
You can use the method
Dependency.proxy()
to easily get a proxy object.
All non-dunder attributes/methods will be grabbed/set on the current object instead of the proxy.
This means you can call all non-special methods and access normal attributes, as if the object was really the currently active dependency instance.
Any methods/attributes that start with a _ will not be used on the proxied object,
but will be used on only the proxy-object it's self.
This means, you should not ask/set any attributes that start with _ (underscore)
when using the proxy object.
Here is an example boto3 s3 resource dependency:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
You can import the proxy and use it as if it's the current S3 object:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
You can use the proxy object like a normal object.
The only things not forwarded are any method/attribute that starts
with a _, which conveays the attribute as private/internal.
This includes any dunder-methods, they are not forarded either.
Only use the proxy object for normal attribute/properties/methods.
If you need do use an attribute/method that starts with an underscore _,
grab the current object directly via S3.grab().
The grab()
method returns the current real object each time it's called (and not a proxy).