summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRene Zhang <rz99@cornell.edu>2015-08-20 18:07:16 -0700
committerRene Zhang <rz99@cornell.edu>2015-08-20 18:07:16 -0700
commit562770be06efd98e157f16cb838bce781be91775 (patch)
tree4bcbb9e51117df4b169102898dd7da1ca5677372
parent7a37a32a84a322d8c64b8ecd508e0dd9f34b995c (diff)
downloadpylint-562770be06efd98e157f16cb838bce781be91775.tar.gz
Fix crash when handling generator inside with context
-rw-r--r--pylint/checkers/typecheck.py7
-rw-r--r--pylint/test/functional/with_using_generator.py14
-rw-r--r--pylint/test/functional/with_using_generator.txt1
3 files changed, 19 insertions, 3 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index a0f1e5e..04b2c9d 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -29,6 +29,7 @@ from astroid import (
MroError, SuperError, YES, Instance
)
from astroid.bases import BUILTINS
+from astroid.bases import NodeNG
from astroid import objects
from astroid import helpers
import six
@@ -48,11 +49,11 @@ _ZOPE_DEPRECATED = (
def _unflatten(iterable):
for elem in iterable:
- elem = elem[0]
- if isinstance(elem, collections.Sequence):
+ if (isinstance(elem, collections.Sequence) and
+ not isinstance(elem, basestring)):
for subelem in _unflatten(elem):
yield subelem
- else:
+ elif isinstance(elem, NodeNG):
yield elem
diff --git a/pylint/test/functional/with_using_generator.py b/pylint/test/functional/with_using_generator.py
new file mode 100644
index 0000000..25c6b37
--- /dev/null
+++ b/pylint/test/functional/with_using_generator.py
@@ -0,0 +1,14 @@
+""" Testing with statements that use generators. This should not crash. """
+
+class Base(object):
+ """ Base class. """
+ val = 0
+
+ def gen(self):
+ """ A generator. """
+ yield self.val
+
+ def fun(self):
+ """ With statement using a generator. """
+ with self.gen(): # [not-context-manager]
+ pass
diff --git a/pylint/test/functional/with_using_generator.txt b/pylint/test/functional/with_using_generator.txt
new file mode 100644
index 0000000..276b05c
--- /dev/null
+++ b/pylint/test/functional/with_using_generator.txt
@@ -0,0 +1 @@
+not-context-manager:13:Base.fun:Context manager 'generator' doesn't implement __enter__ and __exit__.