Skip to content

Conversation

@opalczynski
Copy link
Contributor

No description provided.

@opalczynski
Copy link
Contributor Author

@dancio will be nice if you would take a look.

@dancio
Copy link
Contributor

dancio commented Apr 27, 2016

lgtm

class GeoPoint(Field):
class GeoPointStruct(object):

def __init__(self, latitude=None, longitude=None, distance=None, unit=None):
Copy link
Contributor

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 ?

Copy link
Contributor

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)
@opalczynski
Copy link
Contributor Author

@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):
Copy link
Contributor

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'

Copy link
Member

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 ;)

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@opalczynski opalczynski merged commit cde49ec into develop Apr 29, 2016
@opalczynski opalczynski deleted the LIB-653 branch April 29, 2016 12:55
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 this pull request may close these issues.

6 participants