-
Notifications
You must be signed in to change notification settings - Fork 534
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
CRS.__eq__ crash on inconsistent types #1439
Comments
👋 @drnextgis this is expected, Sean also mentioned that from rasterio 1.0 CRS equality should only works between CRS object (#1357). CRS are object, you cannot compare an object with an int in my opinion so raising an error is the expected behavior and masking it could be dangerous. Hope this answer is 👌. |
@drnextgis can we close here ? |
@vincentsarago thanks for reply. |
Is it really necessary to raise an exception here? Throughout Python, equality between objects of different types is implemented and returns normally, for example:
This crashes my code, because I configured my ORM (SQLAlchemy) to store a CRS as a WKT string, and convert it back to a rasterio CRS object when loading data. When the database entry is NULL, that leads SQLAlchemy to compare a CRS with
I think SQLAlchemy is making the reasonable assumption that equality will always return something, because the Python docs say that:
So even though the docs don't explicitly say "raising an exception for inconsistent types is forbidden", they imply that a comparison between inconsistent types returns False or NotImplemented. Equality is often implemented by first checking type consistence, then comparing the values if types are consistent. I think this would be more sensible, because crashing in Of course, this means that some logic error will be silenced, but that's a design decision by the Python devs, and it's (as far as I can tell) the norm in all common Python libraries, as well as in the standard library. |
Related: #1754 |
I see, the problem is that this code only catches For example, this code: from rasterio.crs import CRS
CRS.from_epsg(4326) == 1111111111111111111 raises an
Should I open a new issue for this? |
We are using
rasterio
intelluric
library and got the following issue: satellogic/telluric#123. The root cause of this issue is thatCRS.__eq__
crashes on inconsistent types. What do you think about it?The text was updated successfully, but these errors were encountered: