-
Notifications
You must be signed in to change notification settings - Fork 8
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
Lazy proxy dict #1
Comments
Ok, so I think if we made |
Does that also fakes the own identity? Like |
Yes, I believe that it does. The following script: t.py from lazyasd import LazyObject
x = LazyObject(dict, globals(), 'x')
print(isinstance(x, dict))
print(type(x))
print(x) yields: scopatz@localhost ~/temp $ python t.py
True
<class 'dict'>
{} |
Ok, the main problem here is that in the above example the object is resolved on the In [6]: def dicter():
...: print("Resolving")
...: return {}
...:
In [7]: x = LazyObject(dicter, globals(), 'x')
In [8]: print(isinstance(x, dict))
Resolving
True Basically I need an object which looks like a dict and only does the "work" of becoming one when a real value is used. d = LaszyProxyDict(loader)
isinstance(d, dict) # true, but loader isn't called yet
try:
d == {...} # doesn't compare, but raises / used internally by the traitlet on assignment to figure out if the value is changed to the earlier (=empty) one
except:
print("not yet loaded...")
d["something"] # triggers loading
d == {...} # now returns True or False I could think of a The equal behaviour is basically a specific problem of traitlets (the normal |
Ahh yeah I see. Yeah, we probably want a ProxyObject class then. I think in the constructor you need to save the target type in This would be a great addition to have. Alternatively we could also do this in the LazyObject with a kwarg called Or we could generalize this and make it so that LazyObject takes |
The latter sounds great. I think I could even get around subclassing if this would also take functions... So basically this would mean that the basic algo in
What I'm not quite understand is why the rest of the functions are fleshed out (e.g. |
All those functions are fleshed out because Python doens't necessarily go through |
My guess is that it would, though. I don't think all of those functions need to be changed. And if they do, there is probably a way to abstract that in |
Another question: is it ok to switch this project to py2+ instead of py3 only? |
Yep, this can be py2k friendly as long as it also works well with amalgamate. |
One of the reasons for splitting this and amalgamate out from xonsh was to make the more broadly available, including other versions of Python |
[Continuing the conversation from https://twitter.com/scopatz/status/756544618964004868]
Usage is in the environment kernel manager: It activates a conda env to get the environment variables (mostly for the altered PATH element, but I guess there could be others as well) and passes that on to the notebook server to use as a new environment variables for the started kernel. Before using the lazy proxy, starting up a notebook server took a lot of seconds (and the notebook page showed nothing) due to activating all envs which I had installed. Now it's as fast as usual and the
activate
only happens when the kernel is used for the first time.The text was updated successfully, but these errors were encountered: