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

Allow importing pure-Python implementation without setting WRAPT_DISABLE_EXTENSIONS variable #235

Open
NiklasRosenstein opened this issue Apr 16, 2023 · 1 comment

Comments

@NiklasRosenstein
Copy link

Without setting the WRAPT_DISABLE_EXTENSIONS environment variable, there is currently no way to specifically import the pure Python implementation of ObjectProxy.

My use case requires the Python implementation to allow me to overwrite an attribute on the ObjectProxy object without modifying the attribute on the wrapped object.

wrapper = ObjectProxy(obj)
object.__setattr__(wrapper, "mymethod", wrapped_mymethod)

assert obj.mymethod is not wrapped_mymethod
assert wrapper.mymethod is wrapped_mymethod
@NiklasRosenstein
Copy link
Author

A hacky workaround I found:

attrs = {"mymethod": staticmethod(wrapped_mymethod)}
proxy_cls = type('Proxy', (ObjectProxy,), attrs)
wrapper = proxy_cls(obj)

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

1 participant