diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-29 22:11:22 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-11-29 22:11:22 +0200 |
commit | 01660061a050c2f0df9c60b91c82f2fe89a651b4 (patch) | |
tree | f7984e064f1cae3d7fbab7493382aecb6d5ce142 /astroid/util.py | |
parent | 6963c74ffb9e69b5af8d376078dcb7ab1596a906 (diff) | |
download | astroid-git-01660061a050c2f0df9c60b91c82f2fe89a651b4.tar.gz |
Add support for handling Uninferable nodes when calling as_string
Some object, for instance List or Tuple can have, after inference,
Uninferable as their elements, happening when their components
weren't couldn't be inferred properly. This means that as_string
needs to cope with expecting Uninferable nodes part of the other
nodes coming for a string transformation. The patch adds a visit
method in AsString and ``accept`` on Yes / Uninferable nodes.
Closes issue #270.
Diffstat (limited to 'astroid/util.py')
-rw-r--r-- | astroid/util.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/astroid/util.py b/astroid/util.py index 1d50f7be..40c0fb25 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -37,17 +37,23 @@ class Uninferable(object): """Special inference object, which is returned when inference fails.""" def __repr__(self): return 'Uninferable' + __str__ = __repr__ def __getattribute__(self, name): if name == 'next': raise AttributeError('next method should not be called') if name.startswith('__') and name.endswith('__'): return object.__getattribute__(self, name) + if name == 'accept': + return object.__getattribute__(self, name) return self def __call__(self, *args, **kwargs): return self + def accept(self, visitor): + func = getattr(visitor, "visit_uninferable") + return func(self) class BadOperationMessage(object): """Object which describes a TypeError occurred somewhere in the inference chain |