Skip to content
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

Python API has bad error message on no attribute (`object has no __getattr__`) #1677

Closed
FHTMitchell opened this issue Jun 25, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@FHTMitchell
Copy link

commented Jun 25, 2019

I would expect

ds = gdal.Open(str(pan_imgs[0]))
ds.BAD_ATTRIBUTE

to produce the useful error message (along the lines of)

AttrributeError: 'Driver' object has no attribute 'BAD_ATTRIBUTE'

but instead we get the following rather confusing and uninformative traceback

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-4d14d3792bfe> in <module>
      1 ds = gdal.Open(str(pan_imgs[0]))
----> 2 ds.BAD_ATTRIBUTE()

C:\Programs\Anaconda3\lib\site-packages\osgeo\gdal.py in <lambda>(self, name)
   1861     for _s in [MajorObject]:
   1862         __swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
-> 1863     __getattr__ = lambda self, name: _swig_getattr(self, Dataset, name)
   1864 
   1865     def __init__(self, *args, **kwargs):

C:\Programs\Anaconda3\lib\site-packages\osgeo\gdal.py in _swig_getattr(self, class_type, name)
     72 
     73 def _swig_getattr(self, class_type, name):
---> 74     return _swig_getattr_nondynamic(self, class_type, name, 0)
     75 
     76 

C:\Programs\Anaconda3\lib\site-packages\osgeo\gdal.py in _swig_getattr_nondynamic(self, class_type, name, static)
     67         return method(self)
     68     if (not static):
---> 69         return object.__getattr__(self, name)
     70     else:
     71         raise AttributeError(name)

AttributeError: type object 'object' has no attribute '__getattr__'

We can see the error is system independent and appears in the latest version here.

The problem is that SWIG incorrectly uses object.__getattr__ instead of getattr() or object.__getattribute__. This was raised to the SWIG team in 2016 as issue 588 and fixed in patch 598 so updating the version of SWIG used should fix the problem.

@rouault rouault closed this in ec4d909 Jun 25, 2019

@rouault rouault added this to the 3.1.0 milestone Jun 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.