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

WKBElement class has no __bool__ method #243

Open
alkment opened this issue Aug 21, 2019 · 4 comments
Open

WKBElement class has no __bool__ method #243

alkment opened this issue Aug 21, 2019 · 4 comments

Comments

@alkment
Copy link

alkment commented Aug 21, 2019

It seems like currently WKBElment objects returned by queries don't have a bool method thus it's not easy to implement logic that conditions on the ORM model having a non null GIS field.

What do you think about adding the following ?

def __bool__(self):
    return True
@adrien-berchet
Copy link
Member

I am not sure of what you want to achieve but can't you just check whether your wkb object is None or not?

@alkment
Copy link
Author

alkment commented Aug 21, 2019

Checking for None is what I am currently doing.
Other elements returned by sqlalchemy generally have a __bool__ method. So I thought it would be nice if wkb has one too.
If you think there is a reason why it should not close this.

@adrien-berchet
Copy link
Member

Ok, I see your point.
It could be implemented but we have to think a little more about what a WKBElement returning True really is. For example, should a WKBElement containing an empty Geometry still return True? Usually the empty objects return False.

@alkment
Copy link
Author

alkment commented Aug 23, 2019

Yes simply returning True might not make sense especially if the Geometry can be empty.
There could be other instances when returning False might make sense. I am not an expert on this datatype.

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

2 participants