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 deal with is? #64

Open
emiel opened this issue Jan 31, 2022 · 4 comments
Open

How to deal with is? #64

emiel opened this issue Jan 31, 2022 · 4 comments

Comments

@emiel
Copy link

emiel commented Jan 31, 2022

I have run in to the following:

p = Proxy(..)

if p is None:
  """Always false"""

I don't know that there is a way to proxy is (identity) but it would be nice to have a way to ensure the proxy is evaluated.

Now I'm using:

p = Proxy(..)

if p.__wrapped__ is None:
    pass

But that looks a bit ugly? Any suggestions? Perhaps something in "utils.py" to force evaluation?

Thanks!

@ionelmc
Copy link
Owner

ionelmc commented Jan 31, 2022

The is operator basically does a pointer check - "are those objects at the same memory address?" basically. There's no way to hook into this process. Using p.__wrapped__ is probably the best thing to do.

I guess there could be an unproxy or similar in utils somewhere tho. Why do you need this? How often do you have this usecase?

@emiel
Copy link
Author

emiel commented Feb 5, 2022

Thanks for your reply. I ran into lazy_object_proxy while working with Airflow. In particular while using Context: https://github.com/apache/airflow/blob/39e395f9816c04ef2f033eb0b4f635fc3018d803/airflow/utils/context.py#L252

In short I believe it is something like this:

import lazy_object_proxy

p1 = lazy_object_proxy.Proxy(lambda: None)


def unproxy(proxy):
    return proxy.__wrapped__


if p1 is None:
    print("None is None")

if unproxy(p1) is None:
    print("None is None")

if not p1:
    print("p1 is falsy")

I've already rewrote my code where I don't need an "unproxy" but it seemed to be missing from the library. I thought proxy.__wrappped__ was quite ugly. ;)

Feel free to close this issue as I'm moving on. Just a bit of friendly feedback. :)

@jayarjo
Copy link

jayarjo commented Jul 8, 2022

@ionelmc I've encountered the same problem now. In brief I was trying to organize a fallback for cases when prev_execution_date_success macro is None and inability to check the value for being None or not was bewildering to say at least. Airflow should definitely mention this somewhere in the macros related doc and maybe even provide an example of how to deal with macros returning None.

@ionelmc
Copy link
Owner

ionelmc commented Dec 15, 2023

So do I need to do something in LOP about this?

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

3 participants