diff options
| author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-06-21 11:54:01 -0600 |
|---|---|---|
| committer | Bryce Guinta <bryce.guinta@protonmail.com> | 2018-06-23 18:26:21 -0600 |
| commit | 27f288b9861f7648de059f88264afc8291590269 (patch) | |
| tree | 3bc7f562cc2838620230af69f0178c5e23fb91d5 /astroid/node_classes.py | |
| parent | a4273963ea10ffbcb9a4351801268c08e3e7e518 (diff) | |
| download | astroid-git-27f288b9861f7648de059f88264afc8291590269.tar.gz | |
Prevent Const copy resulting in recursion
Calling object.__new__ on a Const node would result in infinite recursion
Fix infinite recursion by explicitly raising AttributeError if
__getattr__ is called for value
See https://nedbatchelder.com/blog/201010/surprising_getattr_recursion.html
for more details
Close #565
Diffstat (limited to 'astroid/node_classes.py')
| -rw-r--r-- | astroid/node_classes.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 2236721e..36003fff 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -2300,6 +2300,17 @@ class Const(mixins.NoChildrenMixin, NodeNG, bases.Instance): super(Const, self).__init__(lineno, col_offset, parent) + def __getattr__(self, name): + # This is needed because of Proxy's __getattr__ method. + # Calling object.__new__ on this class without calling + # __init__ would result in an infinite loop otherwise + # since __getattr__ is called when an attribute doesn't + # exist and self._proxied indirectly calls self.value + # and Proxy __getattr__ calls self.value + if name == "value": + raise AttributeError + return super().__getattr__(name) + def getitem(self, index, context=None): """Get an item from this node if subscriptable. |
