Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#7873 closed (fixed)

GEOSGeometry equality operator fails on None

Reported by: denis@… Owned by: jbronn
Component: GIS Version: gis
Severity: Keywords: geos equals
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jbronn)

>>> from django.contrib.gis.geos import *
>>> Point(0, 0) == None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/base.py", line 170, in __eq__
    return self.equals_exact(other)
  File "/Library/Python/2.5/site-packages/django/contrib/gis/geos/base.py", line 318, in equals_exact
    return geos_equalsexact(self.ptr, other.ptr, float(tolerance))
AttributeError: 'NoneType' object has no attribute 'ptr'
>>> 

Attachments (1)

geos_eq.diff (571 bytes) - added by jbronn 7 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by jbronn

  • Description modified (diff)
  • Keywords equals added
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jbronn
  • Patch needs improvement unset

I agree that a TypeError should be raised instead -- at least an error is raised, so this is non-critical at the moment.

Changed 7 years ago by jbronn

comment:2 Changed 7 years ago by jbronn

  • Status changed from new to assigned

On second thought, it would be more pythonic to return False instead. The attached patch does that.

comment:3 Changed 7 years ago by jbronn

  • milestone set to 1.0 beta

comment:4 Changed 7 years ago by denis@…

Agreed about the return False.
This might be useful to check if a geometry is set. While some people will write
if not self.geom:
  ...
Others will write:
if self.geom == None:
  ...

comment:5 Changed 7 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [8040]) gis: Fixed #7873, GEOSGeometry equivalence comparison with None should not raise an exception. Thanks, Denis.

comment:6 Changed 4 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

Note: See TracTickets for help on using tickets.
Back to Top