hasattr() does not work with some builtin types #236

pyjsorg opened this Issue Apr 27, 2012 · 2 comments


None yet
1 participant

pyjsorg commented Apr 27, 2012

When called on monkey-patched objects like String or Number, it will return False even when method/attribute exists and is accessible with getattr():

hasattr("", "find") returns False, but getattr("", "find") returns actual function.

According to python docs, hasattr() SHOULD invoke getattr() and catch AttributeError, http://docs.python.org/library/functions.html#hasattr

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=483 (August 21, 2010 05:06:48)


pyjsorg commented Apr 27, 2012

From cornelis...@gmail.com on February 18, 2011 09:03:32:
Thanks for filing this issue and adding the tests.

There are two issues here. A problem with hasattr(), i.e. hasattr("", "find") should return true. This is fixed in commit e1f9bea..a7896e5

The other tests added for this bug hasattr(1.0, "real") and hasattr(1, "real") will continue to fail, since the method is not implemented.

The implementation of calling getattr and check for exception is technically correct, but would slow down javascript code horrendously. The try/catch in javascript is veeeery slllooowww.

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