Ticket #2926 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Python constructors don't fail properly

Reported by: manderson Owned by: hobu
Priority: low Milestone: 1.7.0
Component: PythonBindings Version: unspecified
Severity: minor Keywords:
Cc: warmerdam, tamas, rouault

Description

The first time I tried out the Python bindings I used the following:

from osgeo import ogr
from osgeo.gdalconst import *

shpdrv = ogr.GetDriverByName?("ESRI Shapefile")
dsloc = shpdrv.CreateDataSource?("outputDir")
# etc etc... Until I was about to add geometry
tstGeo = ogr.Geometry()
tstGeo.AddPoint?(0, 1, 1)

After the AddPoint? call Python failed with a TypeError? in ogr.py: (snip) in AddPoint?

return _ogr.Geometry_AddPoint(*args, **kwargs)

TypeError?: in method 'Geometry_AddPoint', argument 1 of type 'OGRGeometryShadow *'

I realize this is because the Geometry object is not being created in the intended way (I got excited...) but would it be worth it to add docstrings to the init methods in the Python bindings (in general and specifically to ogr.Geometry.init) to provide a gentle introduction for GDAL/Python new people? Perhaps throw a less vague error when this happens?

This is happening using gdal-1.6 and Python 2.6.1, both compiled with GCC 3.4.4 running under Cygwin.

Change History

Changed 4 years ago by warmerdam

  • cc warmerdam added
  • owner changed from warmerdam to hobu
  • component changed from default to PythonBindings

Changed 4 years ago by hobu

  • cc tamas, rouault added

I have attempted to fix this with r16720. Use ogr.UseExceptions?() when you want this to actually throw an exception, otherwise, an error will be printed to stdout.

Changed 4 years ago by rouault

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to 1.7.0
Note: See TracTickets for help on using tickets.