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

How to check whether the proxy is resolved or not #41

Closed
hhsecond opened this issue Jun 27, 2020 · 7 comments · Fixed by #53
Closed

How to check whether the proxy is resolved or not #41

hhsecond opened this issue Jun 27, 2020 · 7 comments · Fixed by #53

Comments

@hhsecond
Copy link

hhsecond commented Jun 27, 2020

Thanks a lot for the wonderful package
I was wondering if there is a mechanism to check whether the factory function is being called or not, may be allowing to check?

if obj.__target__ is None
@ionelmc
Copy link
Owner

ionelmc commented Jun 28, 2020

It would depend on the implementation. I guess I could add a standard way of telling if it holds the instance or not (like obj.__instance__ or similar) but why do you need this anyway?

@ionelmc
Copy link
Owner

ionelmc commented Jun 28, 2020

Thinking more about this, a __isresolved__ bool would be better.

@hhsecond
Copy link
Author

Hi @ionelmc, First of all, thanks a lot for taking your time here. I can't express how grateful I am (and so is the folks using your project)

About your suggestion, __isresolved__ sounds better to me too.
So my need is a bit involved in the architecture level but the gist is here
I have python processes (nodes) composed as DAGs. I prefetch the datapoints from database and provide them as lazy proxies to these nodes. These nodes can use these data points to do different operations but a writer process kept on checking the data changes and write it back to the database. Currently, the assumption I have taken is that, if the data is not resolved then the data is not changed. So I can avoid expensive writes.

While my requirement is quite peculiar, I thought the functionality to check proxy-resolution is quite useful and widely being used already. Currently what I do is to use simple.Proxy and check

"__wrapper__" in proxyobj.__dict__

@ionelmc
Copy link
Owner

ionelmc commented Mar 20, 2021

So I would like to add this property in the next release but I'm not sure about the name. It has to be something unique enough and double underscored (to increase uniqueness). It has to avoid british/american spelling differences, and be pretty obvious.

My candidates:

  • __isresolved__ - bad because of ambiguous spelling - is it resolved or rezolved? who knows
  • __resolved__ - same problem, and also, I wonder if it's worth having the "is" prefix at all
  • __materialized__ - same problem (materialised), also kinda long
  • __completed__
  • __instantiated__ - kinda long, but very good otherwise
  • __has_instance__ - still long
  • __reified__ - short, unique but kinda obscure?
  • __formed__ - maybe not very obvious of what it'd represent?

Hmmm... perhaps there's some terminology already established in the stdlib?

@ionelmc
Copy link
Owner

ionelmc commented Mar 20, 2021

On second thought perhaps reusing terms from stdlib would be a bad idea. So I've found __cached__ which would seem suitable but would conflict with the interface here https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module

@ionelmc
Copy link
Owner

ionelmc commented Mar 22, 2021

How about __called__ or even __factory_called__ (no confusion about if it means that __call__ was used)?

@ionelmc
Copy link
Owner

ionelmc commented Mar 22, 2021

So turns out no one spells "rezolved". Anyway, not using the "is" prefix as it seems to have a "call interface" in the stdlib (eg: somestr.isdigit()).

ionelmc added a commit that referenced this issue Mar 22, 2021
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

Successfully merging a pull request may close this issue.

2 participants