Skip to content

Commit

Permalink
Fixing python attribute lookup
Browse files Browse the repository at this point in the history
Cleans up patch swig#232
Fixes misleading error messages from swig#588

If __getattr__ is called, this means that normal attribute lookup has failed.
  If checking thisown and __swig_getmethods__ fails, then give up and raise
  AttributeError instead of calling the non-existent object.__getattr__.
  Note that in practice the result is essentially the same, since trying to
  access object.__getattr__ fails and raises AttributeError, just with a
  misleading message.
In addition, there's no point in having nondynamic attribute lookup.
  • Loading branch information
ahnolds committed Jan 24, 2016
1 parent 55f303d commit de4b3a4
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Source/Modules/python.cxx
Expand Up @@ -897,15 +897,11 @@ class PYTHON:public Language {
"\n", "def _swig_setattr(self, class_type, name, value):\n", tab4, "return _swig_setattr_nondynamic(self, class_type, name, value, 0)\n\n", NIL);

Printv(f_shadow,
"\n", "def _swig_getattr_nondynamic(self, class_type, name, static=1):\n",
"\n", "def _swig_getattr(self, class_type, name):\n",
tab4, "if (name == \"thisown\"):\n", tab8, "return self.this.own()\n",
tab4, "method = class_type.__swig_getmethods__.get(name, None)\n",
tab4, "if method:\n", tab8, "return method(self)\n",
tab4, "if (not static):\n",
tab4, tab4, "return object.__getattr__(self, name)\n",
tab4, "else:\n",
tab4, tab4, "raise AttributeError(name)\n\n",
"def _swig_getattr(self, class_type, name):\n", tab4, "return _swig_getattr_nondynamic(self, class_type, name, 0)\n\n", NIL);
tab4, "raise AttributeError(\"'%s' object has no attribute '%s'\" % (class_type.__name__, name))\n\n", NIL);

Printv(f_shadow,
"\n", "def _swig_repr(self):\n",
Expand Down

0 comments on commit de4b3a4

Please sign in to comment.