-
Notifications
You must be signed in to change notification settings - Fork 4
[LIB-653] GeoPoint re work, add tests, add possibility to filter; #191
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
Conversation
|
@dancio will be nice if you would take a look. |
|
lgtm |
syncano/models/fields.py
Outdated
| class GeoPoint(Field): | ||
| class GeoPointStruct(object): | ||
|
|
||
| def __init__(self, latitude=None, longitude=None, distance=None, unit=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point is a point, It doesn't have distance, or even radius. What is unit ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if latitude and longitude are required they should not have default values.
… add possibility to define lookup near in such way: GeoLookup(GeoPoint(lat, lng), distance, unit)
|
@forgems test are running - and will probably fail, but you can take a look into correctness :) |
|
|
||
| if not isinstance(value, GeoPointStruct): | ||
| raise SyncanoValueError('Expected an GeoPointStruct') | ||
| if not isinstance(value, GeoPoint): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of checks can be done with assertions like that https://wiki.python.org/moin/UsingAssertionsEffectively:
assert isinstance(value, GeoPoint), 'Expected GeoPoint'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using asserts in code that is meant to be normally used (outside of tests) is baaad. Especially for validations.
python -O and suddenly my validations do not work ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last time I was running python with -O flag was in 2007. It doesn't give you any kind of advantage :) Maybe if you run your tests with -O flag, then it would be a problem, but otherwise IMHO it's ok. And it's the official way for type assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not exactly. It's official in terms of places where the object is actually used. This is a validation function so these are two different things to me. Never seen an assert in a validator of any kind. Although it's likely that main reason for this is the fact that we want a specific Exception class that can be handled rather than AssertionError which suggests something went very wrong.
Anyway, python promotes duck-typing heavily and doesn't like using isinstance. In my opinion that's why they are ok with asserts officially. But coming from C/C++ background, depending on asserts is well, ugly.
Also, kind of unrelated - it's pretty ridiculous that they changed in 3.x print into a function but assert is still a statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me not like asserts in such context - so leave it that way.
No description provided.