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

getattr with non existent attribute returns RuntimeError #7

Closed
dopplershift opened this issue Feb 26, 2014 · 4 comments
Closed

getattr with non existent attribute returns RuntimeError #7

dopplershift opened this issue Feb 26, 2014 · 4 comments

Comments

@dopplershift
Copy link
Member

From david.huard on September 17, 2008 10:18:17

Given a netCDF4 variable var, the following raises a RuntimeError

getattr(var, 'sillyattribute', None)

I would rather expect this to return None.

My guess is that getattr expects var.getattr to return an
AttributeError if the attribute is not found. Since it gets a RuntimeError,
the default value is not returned.

Original issue: http://code.google.com/p/netcdf4-python/issues/detail?id=7

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on September 17, 2008 09:36:59

Your diagnosis was correct. Fixed now in svn revision 571 .

@dopplershift
Copy link
Member Author

From david.huard on October 07, 2008 07:39:47

There is a similar problem with MFDataset::

def __getattr__(self,name):
    if name == 'shape': return self._shape()
    if name == 'ndim': return len(self._shape())
    return self.__dict__[name]

If name is not in dict, it raises a KeyError, instead of the AttributeError that
is needed for the default in getattr to kick in. I've written a small fix, but I have
no clue how to compile the pyx file correctly.

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on October 14, 2008 15:47:53

David: This should be fixed now ( r576 ).

-Jeff

@dopplershift
Copy link
Member Author

From david.huard on February 03, 2009 07:06:07

Closing fixed ticket.

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant