diff options
author | David Shea <dshea@redhat.com> | 2014-07-07 10:10:56 -0400 |
---|---|---|
committer | David Shea <dshea@redhat.com> | 2014-07-07 10:10:56 -0400 |
commit | 2a45373090e129807c45c4b7d9eb35a4ea94f117 (patch) | |
tree | d7544884f79972dbdca136468d49912d61893ce4 /checkers | |
parent | 9b46e20c59729b46135ce777c6b30a164927798a (diff) | |
download | pylint-2a45373090e129807c45c4b7d9eb35a4ea94f117.tar.gz |
Clean up some stylistic issues in the sequence and slice index type checks.
Diffstat (limited to 'checkers')
-rw-r--r-- | checkers/typecheck.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/checkers/typecheck.py b/checkers/typecheck.py index 395e1b7..f0c8034 100644 --- a/checkers/typecheck.py +++ b/checkers/typecheck.py @@ -86,11 +86,6 @@ MSGS = { with an __index__ method.'), } -if sys.version_info >= (3,0): - BUILTINS = 'builtins' -else: - BUILTINS = '__builtin__' - def _determine_callable(callable_obj): # Ordering is important, since BoundMethod is a subclass of UnboundMethod, # and Function inherits Lambda. @@ -550,8 +545,11 @@ accessed. Python regular expressions are accepted.'} # sequence types but skip classes that override __getitem__ and # which may allow non-integer indices. try: - getitem = parent_type.getattr('__getitem__')[0] - except (astroid.NotFoundError, IndexError, TypeError): + getitems = parent_type.getattr('__getitem__') + if getitems is astroid.YES: + return + getitem = getitems[0] + except (astroid.NotFoundError, IndexError): return if not isinstance(getitem, astroid.Function): @@ -560,11 +558,10 @@ accessed. Python regular expressions are accepted.'} if not getitem.parent: return - if not isinstance(getitem.parent.parent, astroid.Module) or \ - getitem.parent.parent.name != BUILTINS: + if getitem.root() != BUILTINS: return - if not getitem.parent.name in sequence_types: + if getitem.parent.name not in sequence_types: return index_type = safe_infer(node) @@ -583,10 +580,9 @@ accessed. Python regular expressions are accepted.'} try: index_type.getattr('__index__') + return except astroid.NotFoundError: pass - else: - return # Anything else is an error self.add_message('invalid-sequence-index', node=node) @@ -619,10 +615,9 @@ accessed. Python regular expressions are accepted.'} try: index_type.getattr('__index__') + return except astroid.NotFoundError: pass - else: - return # Anything else is an error self.add_message('invalid-slice-index', node=node) |