-
Notifications
You must be signed in to change notification settings - Fork 3
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
ObservableModule #8
Comments
Can you elaborate a little on this? Something like a subclass of Observable that tracks changes to a module's |
Ya, that is roughly what I had in mind. And if recursive, then also the containers within the module. And tracking |
Ideally something like import sys, pydispatch
sys_change_emitter = pydispatch.wrap(sys) |
In order to do that, the module's I'm not sure how that would impact the module's references to its own objects at that point though. For pure-python modules, it may be fine, but for modules relying on binary extensions (like most of Python's standard lib) there could be some crazy side effects. If doing that recursively, other imported modules (since they're in the It sounds like fun, lol! But I think it'd be hard to keep things from breaking |
According to https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy a module's
|
ya, the >>> import os
>>> len(os.__dict__.keys())
344
>>> os.__dict__['foo'] = 'bar'
>>> len(os.__dict__.keys())
345
>>> os.__dict__ = dict(os.__dict__)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: readonly attribute But the wrapper will need to create a new module object. Last time I did this, I used a normal class as the module wrapper (e.g. https://github.com/rinslow/fakeos/blob/master/fakeos.py#L13), and added module-like attributes so it acted like a module, like https://github.com/Akrog/modulefaker/blob/master/modulefaker/__init__.py#L35. More modern attempts use the new import machinery voodoo to create real module objects which inherit from the correct classes. |
"module proxy" should be a good term, except it is full of http proxy stuff. Lazy module loaders may be useful to see how to do this, and search results tend to be more useful. https://github.com/cacilhas/ObjectProxy |
It would be very handy to have an
ObservableModule
, especially forsys
in order to identify which code is making changes there.The text was updated successfully, but these errors were encountered: