summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/b/bad_builtin_extension.py4
-rw-r--r--tests/functional/b/bad_builtin_extension.rc2
-rw-r--r--tests/functional/b/bad_builtin_extension.txt2
-rw-r--r--tests/functional/b/broad_try_clause_extension.py49
-rw-r--r--tests/functional/b/broad_try_clause_extension.rc2
-rw-r--r--tests/functional/b/broad_try_clause_extension.txt4
-rw-r--r--tests/functional/c/compare_to_zero_extension.py28
-rw-r--r--tests/functional/c/compare_to_zero_extension.rc2
-rw-r--r--tests/functional/c/compare_to_zero_extension.txt4
-rw-r--r--tests/functional/d/docstyle_extension.py41
-rw-r--r--tests/functional/d/docstyle_extension.rc2
-rw-r--r--tests/functional/d/docstyle_extension.txt7
-rw-r--r--tests/functional/e/elif_checker.py27
-rw-r--r--tests/functional/e/elif_checker.rc2
-rw-r--r--tests/functional/e/elif_checker.txt2
-rw-r--r--tests/functional/e/empty_comment.py13
-rw-r--r--tests/functional/e/empty_comment.rc2
-rw-r--r--tests/functional/e/empty_comment.txt4
-rw-r--r--tests/functional/e/empty_string_comparison.py16
-rw-r--r--tests/functional/e/empty_string_comparison.rc2
-rw-r--r--tests/functional/e/empty_string_comparison.txt4
-rw-r--r--tests/functional/m/mccabe.py216
-rw-r--r--tests/functional/m/mccabe.rc4
-rw-r--r--tests/functional/m/mccabe.txt15
-rw-r--r--tests/functional/o/overlapping_exceptions.py66
-rw-r--r--tests/functional/o/overlapping_exceptions.rc2
-rw-r--r--tests/functional/o/overlapping_exceptions.txt12
-rw-r--r--tests/functional/r/redefined_variable_type.py85
-rw-r--r--tests/functional/r/redefined_variable_type.rc2
-rw-r--r--tests/functional/r/redefined_variable_type.txt10
30 files changed, 631 insertions, 0 deletions
diff --git a/tests/functional/b/bad_builtin_extension.py b/tests/functional/b/bad_builtin_extension.py
new file mode 100644
index 000000000..fd3e5c054
--- /dev/null
+++ b/tests/functional/b/bad_builtin_extension.py
@@ -0,0 +1,4 @@
+# pylint: disable=missing-docstring
+
+TEST = map(str, (1, 2, 3)) # [bad-builtin]
+TEST1 = filter(str, (1, 2, 3)) # [bad-builtin]
diff --git a/tests/functional/b/bad_builtin_extension.rc b/tests/functional/b/bad_builtin_extension.rc
new file mode 100644
index 000000000..de9b4244a
--- /dev/null
+++ b/tests/functional/b/bad_builtin_extension.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.bad_builtin,
diff --git a/tests/functional/b/bad_builtin_extension.txt b/tests/functional/b/bad_builtin_extension.txt
new file mode 100644
index 000000000..e074657b2
--- /dev/null
+++ b/tests/functional/b/bad_builtin_extension.txt
@@ -0,0 +1,2 @@
+bad-builtin:3:7::Used builtin function 'map'. Using a list comprehension can be clearer.:HIGH
+bad-builtin:4:8::Used builtin function 'filter'. Using a list comprehension can be clearer.:HIGH
diff --git a/tests/functional/b/broad_try_clause_extension.py b/tests/functional/b/broad_try_clause_extension.py
new file mode 100644
index 000000000..6fc85c6b2
--- /dev/null
+++ b/tests/functional/b/broad_try_clause_extension.py
@@ -0,0 +1,49 @@
+# pylint: disable=missing-docstring, invalid-name
+
+MY_DICTIONARY = {"key_one": 1, "key_two": 2, "key_three": 3}
+
+try: # [too-many-try-statements]
+ value = MY_DICTIONARY["key_one"]
+ value += 1
+ print("This one has an except clause only.")
+except KeyError:
+ pass
+
+try: # [too-many-try-statements]
+ value = MY_DICTIONARY["key_one"]
+ value += 1
+ print("This one has a finally clause only.")
+finally:
+ pass
+
+try: # [too-many-try-statements]
+ value = MY_DICTIONARY["key_one"]
+ value += 1
+ print("This one has an except clause...")
+ print("and also a finally clause!")
+except KeyError:
+ pass
+finally:
+ pass
+
+try: # [too-many-try-statements]
+ if "key_one" in MY_DICTIONARY:
+ entered_if_body = True
+ print("This verifies that content inside of an if statement is counted too.")
+ else:
+ entered_if_body = False
+
+ while False:
+ print("This verifies that content inside of a while loop is counted too.")
+
+ for item in []:
+ print("This verifies that content inside of a for loop is counted too.")
+
+
+except KeyError:
+ pass
+
+try:
+ value = MY_DICTIONARY["key_one"]
+except KeyError:
+ value = 0
diff --git a/tests/functional/b/broad_try_clause_extension.rc b/tests/functional/b/broad_try_clause_extension.rc
new file mode 100644
index 000000000..1737783e0
--- /dev/null
+++ b/tests/functional/b/broad_try_clause_extension.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.broad_try_clause,
diff --git a/tests/functional/b/broad_try_clause_extension.txt b/tests/functional/b/broad_try_clause_extension.txt
new file mode 100644
index 000000000..8f97f9b24
--- /dev/null
+++ b/tests/functional/b/broad_try_clause_extension.txt
@@ -0,0 +1,4 @@
+too-many-try-statements:5:0::try clause contains 3 statements, expected at most 1:HIGH
+too-many-try-statements:12:0::try clause contains 3 statements, expected at most 1:HIGH
+too-many-try-statements:19:0::try clause contains 4 statements, expected at most 1:HIGH
+too-many-try-statements:29:0::try clause contains 7 statements, expected at most 1:HIGH
diff --git a/tests/functional/c/compare_to_zero_extension.py b/tests/functional/c/compare_to_zero_extension.py
new file mode 100644
index 000000000..29fd13994
--- /dev/null
+++ b/tests/functional/c/compare_to_zero_extension.py
@@ -0,0 +1,28 @@
+# pylint: disable=literal-comparison,missing-docstring
+
+X = 123
+Y = len('test')
+
+if X is 0: # [compare-to-zero]
+ pass
+
+if Y is not 0: # [compare-to-zero]
+ pass
+
+if X == 0: # [compare-to-zero]
+ pass
+
+if Y != 0: # [compare-to-zero]
+ pass
+
+if X > 0:
+ pass
+
+if X < 0:
+ pass
+
+if 0 < X:
+ pass
+
+if 0 > X:
+ pass
diff --git a/tests/functional/c/compare_to_zero_extension.rc b/tests/functional/c/compare_to_zero_extension.rc
new file mode 100644
index 000000000..e9b836539
--- /dev/null
+++ b/tests/functional/c/compare_to_zero_extension.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.comparetozero,
diff --git a/tests/functional/c/compare_to_zero_extension.txt b/tests/functional/c/compare_to_zero_extension.txt
new file mode 100644
index 000000000..c5862e1b7
--- /dev/null
+++ b/tests/functional/c/compare_to_zero_extension.txt
@@ -0,0 +1,4 @@
+compare-to-zero:6:3::Avoid comparisons to zero:HIGH
+compare-to-zero:9:3::Avoid comparisons to zero:HIGH
+compare-to-zero:12:3::Avoid comparisons to zero:HIGH
+compare-to-zero:15:3::Avoid comparisons to zero:HIGH
diff --git a/tests/functional/d/docstyle_extension.py b/tests/functional/d/docstyle_extension.py
new file mode 100644
index 000000000..a5b6161b0
--- /dev/null
+++ b/tests/functional/d/docstyle_extension.py
@@ -0,0 +1,41 @@
+"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'"""
+
+
+def check_messages(*messages): # [docstring-first-line-empty]
+ """
+ docstring"""
+ return messages
+
+
+def function2():
+ """Test Ok"""
+
+
+class FFFF: # [docstring-first-line-empty]
+ """
+ Test Docstring First Line Empty
+ """
+
+ def method1(self): # [docstring-first-line-empty, bad-docstring-quotes]
+ '''
+ Test Triple Single Quotes docstring
+ '''
+
+ def method2(self): # [bad-docstring-quotes]
+ "bad docstring 1"
+
+ def method3(self): # [bad-docstring-quotes]
+ 'bad docstring 2'
+
+ def method4(self): # [bad-docstring-quotes]
+ ' """bad docstring 3 '
+
+ @check_messages("bad-open-mode", "redundant-unittest-assert", "deprecated-module")
+ def method5(self):
+ """Test OK 1 with decorators"""
+
+ def method6(self):
+ r"""Test OK 2 with raw string"""
+
+ def method7(self):
+ u"""Test OK 3 with unicode string"""
diff --git a/tests/functional/d/docstyle_extension.rc b/tests/functional/d/docstyle_extension.rc
new file mode 100644
index 000000000..5128289ff
--- /dev/null
+++ b/tests/functional/d/docstyle_extension.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.docstyle,
diff --git a/tests/functional/d/docstyle_extension.txt b/tests/functional/d/docstyle_extension.txt
new file mode 100644
index 000000000..8a30eedee
--- /dev/null
+++ b/tests/functional/d/docstyle_extension.txt
@@ -0,0 +1,7 @@
+docstring-first-line-empty:4:0:check_messages:First line empty in function docstring:HIGH
+docstring-first-line-empty:14:0:FFFF:First line empty in class docstring:HIGH
+bad-docstring-quotes:19:4:FFFF.method1:"Bad docstring quotes in method, expected """""", given '''":HIGH
+docstring-first-line-empty:19:4:FFFF.method1:First line empty in method docstring:HIGH
+bad-docstring-quotes:24:4:FFFF.method2:"Bad docstring quotes in method, expected """""", given """:HIGH
+bad-docstring-quotes:27:4:FFFF.method3:"Bad docstring quotes in method, expected """""", given '":HIGH
+bad-docstring-quotes:30:4:FFFF.method4:"Bad docstring quotes in method, expected """""", given '":HIGH
diff --git a/tests/functional/e/elif_checker.py b/tests/functional/e/elif_checker.py
new file mode 100644
index 000000000..b9722f349
--- /dev/null
+++ b/tests/functional/e/elif_checker.py
@@ -0,0 +1,27 @@
+"""Checks use of "else if" triggers a refactor message"""
+
+
+def my_function():
+ """docstring"""
+ myint = 2
+ if myint > 5:
+ pass
+ else:
+ if myint <= 5: # [else-if-used]
+ pass
+ else:
+ myint = 3
+ if myint > 2:
+ if myint > 3:
+ pass
+ elif myint == 3:
+ pass
+ elif myint < 3:
+ pass
+ else:
+ if myint: # [else-if-used]
+ pass
+ else:
+ if myint:
+ pass
+ myint = 4
diff --git a/tests/functional/e/elif_checker.rc b/tests/functional/e/elif_checker.rc
new file mode 100644
index 000000000..b9b1de49d
--- /dev/null
+++ b/tests/functional/e/elif_checker.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.check_elif,
diff --git a/tests/functional/e/elif_checker.txt b/tests/functional/e/elif_checker.txt
new file mode 100644
index 000000000..43d1e3b1e
--- /dev/null
+++ b/tests/functional/e/elif_checker.txt
@@ -0,0 +1,2 @@
+else-if-used:10:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
+else-if-used:22:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
diff --git a/tests/functional/e/empty_comment.py b/tests/functional/e/empty_comment.py
new file mode 100644
index 000000000..6adaa4fc1
--- /dev/null
+++ b/tests/functional/e/empty_comment.py
@@ -0,0 +1,13 @@
+"""empty-comment test-case"""
+# +1:[empty-comment]
+A = 5 #
+# +1:[empty-comment]
+#
+A = '#' + '1'
+# +1:[empty-comment]
+print(A) #
+print("A=", A) # should not be an error#
+# +1:[empty-comment]
+A = "#pe\0ace#love#" #
+A = "peace#love" # \0 peace'#'''' love#peace'''-'#love'-"peace#love"#
+#######
diff --git a/tests/functional/e/empty_comment.rc b/tests/functional/e/empty_comment.rc
new file mode 100644
index 000000000..1bbd021e7
--- /dev/null
+++ b/tests/functional/e/empty_comment.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.empty_comment,
diff --git a/tests/functional/e/empty_comment.txt b/tests/functional/e/empty_comment.txt
new file mode 100644
index 000000000..ae4eee33e
--- /dev/null
+++ b/tests/functional/e/empty_comment.txt
@@ -0,0 +1,4 @@
+empty-comment:3:0::Line with empty comment:HIGH
+empty-comment:5:0::Line with empty comment:HIGH
+empty-comment:8:0::Line with empty comment:HIGH
+empty-comment:11:0::Line with empty comment:HIGH
diff --git a/tests/functional/e/empty_string_comparison.py b/tests/functional/e/empty_string_comparison.py
new file mode 100644
index 000000000..c6dcf8ea8
--- /dev/null
+++ b/tests/functional/e/empty_string_comparison.py
@@ -0,0 +1,16 @@
+# pylint: disable=literal-comparison,missing-docstring
+
+X = ''
+Y = 'test'
+
+if X is '': # [compare-to-empty-string]
+ pass
+
+if Y is not "": # [compare-to-empty-string]
+ pass
+
+if X == "": # [compare-to-empty-string]
+ pass
+
+if Y != '': # [compare-to-empty-string]
+ pass
diff --git a/tests/functional/e/empty_string_comparison.rc b/tests/functional/e/empty_string_comparison.rc
new file mode 100644
index 000000000..e6e3ded01
--- /dev/null
+++ b/tests/functional/e/empty_string_comparison.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.emptystring,
diff --git a/tests/functional/e/empty_string_comparison.txt b/tests/functional/e/empty_string_comparison.txt
new file mode 100644
index 000000000..7e31c3d25
--- /dev/null
+++ b/tests/functional/e/empty_string_comparison.txt
@@ -0,0 +1,4 @@
+compare-to-empty-string:6:3::Avoid comparisons to empty string:HIGH
+compare-to-empty-string:9:3::Avoid comparisons to empty string:HIGH
+compare-to-empty-string:12:3::Avoid comparisons to empty string:HIGH
+compare-to-empty-string:15:3::Avoid comparisons to empty string:HIGH
diff --git a/tests/functional/m/mccabe.py b/tests/functional/m/mccabe.py
new file mode 100644
index 000000000..b5a257b1f
--- /dev/null
+++ b/tests/functional/m/mccabe.py
@@ -0,0 +1,216 @@
+# pylint: disable=invalid-name,unnecessary-pass,no-else-return,useless-else-on-loop
+# pylint: disable=undefined-variable,consider-using-sys-exit,unused-variable,too-many-return-statements
+# pylint: disable=redefined-outer-name,useless-object-inheritance,using-constant-test,unused-argument
+# pylint: disable=broad-except, not-context-manager, no-method-argument, no-self-use, unspecified-encoding
+
+"""Checks use of "too-complex" check"""
+
+
+def f1(): # [too-complex]
+ """McCabe rating: 1"""
+ pass
+
+
+def f2(n): # [too-complex]
+ """McCabe rating: 1"""
+ k = n + 4
+ s = k + n
+ return s
+
+
+def f3(n): # [too-complex]
+ """McCabe rating: 3"""
+ if n > 3:
+ return "bigger than three"
+ elif n > 4:
+ return "is never executed"
+ else:
+ return "smaller than or equal to three"
+
+
+def f4(): # [too-complex]
+ """McCabe rating: 2"""
+ for i in range(10):
+ print(i)
+
+
+def f5(mylist): # [too-complex]
+ """McCabe rating: 2"""
+ for i in mylist:
+ print(i)
+ else:
+ print(None)
+
+
+def f6(n): # [too-complex]
+ """McCabe rating: 2"""
+ if n > 4:
+ return f(n - 1)
+ else:
+ return n
+
+
+def f7(): # [too-complex]
+ """McCabe rating: 3"""
+
+ def b():
+ """McCabe rating: 2"""
+
+ def c():
+ """McCabe rating: 1"""
+ pass
+
+ c()
+
+ b()
+
+
+def f8(): # [too-complex]
+ """McCabe rating: 4"""
+ try:
+ print(1)
+ except TypeA:
+ print(2)
+ except TypeB:
+ print(3)
+ else:
+ print(4)
+
+
+def f9(): # [too-complex]
+ """McCabe rating: 9"""
+ myint = 2
+ if myint > 5:
+ pass
+ else:
+ if myint <= 5:
+ pass
+ else:
+ myint = 3
+ if myint > 2:
+ if myint > 3:
+ pass
+ elif myint == 3:
+ pass
+ elif myint < 3:
+ pass
+ else:
+ if myint:
+ pass
+ else:
+ if myint:
+ pass
+ myint = 4
+
+
+def f10(): # [too-complex]
+ """McCabe rating: 11"""
+ myint = 2
+ if myint == 5:
+ return myint
+ elif myint == 6:
+ return myint
+ elif myint == 7:
+ return myint
+ elif myint == 8:
+ return myint
+ elif myint == 9:
+ return myint
+ elif myint == 10:
+ if myint == 8:
+ while True:
+ return True
+ elif myint == 8:
+ with myint:
+ return 8
+ else:
+ if myint == 2:
+ return myint
+ return myint
+ return myint
+
+
+class MyClass1(object):
+ """Class of example to test mccabe"""
+
+ _name = "MyClass" # To force a tail.node=None
+
+ def method1(): # [too-complex]
+ """McCabe rating: 1"""
+ pass
+
+ def method2(self, param1): # [too-complex, too-many-branches]
+ """McCabe rating: 18"""
+ if not param1:
+ pass
+ pass
+ if param1:
+ pass
+ else:
+ pass
+
+ pass
+
+ if param1:
+ pass
+ if param1:
+ pass
+ if param1:
+ pass
+ if param1:
+ pass
+ if param1:
+ pass
+ if param1:
+ pass
+ if param1:
+ for value in range(5):
+ pass
+
+ pass
+ for count in range(6):
+ with open("myfile") as fp:
+ count += 1
+ pass
+ pass
+ try:
+ pass
+ if not param1:
+ pass
+ else:
+ pass
+ if param1:
+ raise BaseException("Error")
+ with open("myfile2") as fp2:
+ pass
+ pass
+ finally:
+ if param1 is not None:
+ pass
+ for count2 in range(8):
+ try:
+ pass
+ except BaseException("Error2"):
+ pass
+ return param1
+
+
+for count in range(10): # [too-complex]
+ if count == 1:
+ exit(0)
+ elif count == 2:
+ exit(1)
+ else:
+ exit(2)
+
+
+def method3(self): # [too-complex]
+ """McCabe rating: 2"""
+ try:
+ if True:
+ pass
+ else:
+ pass
+ finally:
+ pass
+ return True
diff --git a/tests/functional/m/mccabe.rc b/tests/functional/m/mccabe.rc
new file mode 100644
index 000000000..ac96a1eb5
--- /dev/null
+++ b/tests/functional/m/mccabe.rc
@@ -0,0 +1,4 @@
+[MASTER]
+load-plugins=pylint.extensions.mccabe,
+
+max-complexity=0
diff --git a/tests/functional/m/mccabe.txt b/tests/functional/m/mccabe.txt
new file mode 100644
index 000000000..3e4a8431d
--- /dev/null
+++ b/tests/functional/m/mccabe.txt
@@ -0,0 +1,15 @@
+too-complex:9:0:f1:'f1' is too complex. The McCabe rating is 1:HIGH
+too-complex:14:0:f2:'f2' is too complex. The McCabe rating is 1:HIGH
+too-complex:21:0:f3:'f3' is too complex. The McCabe rating is 3:HIGH
+too-complex:31:0:f4:'f4' is too complex. The McCabe rating is 2:HIGH
+too-complex:37:0:f5:'f5' is too complex. The McCabe rating is 2:HIGH
+too-complex:45:0:f6:'f6' is too complex. The McCabe rating is 2:HIGH
+too-complex:53:0:f7:'f7' is too complex. The McCabe rating is 3:HIGH
+too-complex:68:0:f8:'f8' is too complex. The McCabe rating is 4:HIGH
+too-complex:80:0:f9:'f9' is too complex. The McCabe rating is 9:HIGH
+too-complex:106:0:f10:'f10' is too complex. The McCabe rating is 11:HIGH
+too-complex:138:4:MyClass1.method1:'method1' is too complex. The McCabe rating is 1:HIGH
+too-complex:142:4:MyClass1.method2:'method2' is too complex. The McCabe rating is 18:HIGH
+too-many-branches:142:4:MyClass1.method2:Too many branches (20/12):HIGH
+too-complex:198:0::This 'for' is too complex. The McCabe rating is 4:HIGH
+too-complex:207:0:method3:'method3' is too complex. The McCabe rating is 2:HIGH
diff --git a/tests/functional/o/overlapping_exceptions.py b/tests/functional/o/overlapping_exceptions.py
new file mode 100644
index 000000000..c5eab48cc
--- /dev/null
+++ b/tests/functional/o/overlapping_exceptions.py
@@ -0,0 +1,66 @@
+# pylint: disable=missing-docstring
+
+import socket
+
+
+class SomeException(Exception):
+ pass
+
+
+class SubclassException(SomeException):
+ pass
+
+
+AliasException = SomeException
+
+try:
+ pass
+except (SomeException, SomeException): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (SomeException, SubclassException): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (SomeException, AliasException): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (AliasException, SubclassException): # [overlapping-except]
+ pass
+
+try:
+ pass
+# +1:[overlapping-except, overlapping-except, overlapping-except]
+except (SomeException, AliasException, SubclassException):
+ pass
+
+try:
+ pass
+except (ArithmeticError, FloatingPointError): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (ValueError, UnicodeDecodeError): # [overlapping-except]
+ pass
+
+
+try:
+ pass
+except (IOError, OSError): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (socket.error, OSError): # [overlapping-except]
+ pass
+
+try:
+ pass
+except (ConnectionError, socket.error): # [overlapping-except]
+ pass
diff --git a/tests/functional/o/overlapping_exceptions.rc b/tests/functional/o/overlapping_exceptions.rc
new file mode 100644
index 000000000..ad49162c0
--- /dev/null
+++ b/tests/functional/o/overlapping_exceptions.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.overlapping_exceptions,
diff --git a/tests/functional/o/overlapping_exceptions.txt b/tests/functional/o/overlapping_exceptions.txt
new file mode 100644
index 000000000..6669ae0f8
--- /dev/null
+++ b/tests/functional/o/overlapping_exceptions.txt
@@ -0,0 +1,12 @@
+overlapping-except:18:7::Overlapping exceptions (SomeException and SomeException are the same):HIGH
+overlapping-except:23:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH
+overlapping-except:28:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH
+overlapping-except:33:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH
+overlapping-except:39:7::Overlapping exceptions (AliasException is an ancestor class of SubclassException):HIGH
+overlapping-except:39:7::Overlapping exceptions (SomeException and AliasException are the same):HIGH
+overlapping-except:39:7::Overlapping exceptions (SomeException is an ancestor class of SubclassException):HIGH
+overlapping-except:44:7::Overlapping exceptions (ArithmeticError is an ancestor class of FloatingPointError):HIGH
+overlapping-except:49:7::Overlapping exceptions (ValueError is an ancestor class of UnicodeDecodeError):HIGH
+overlapping-except:55:7::Overlapping exceptions (IOError and OSError are the same):HIGH
+overlapping-except:60:7::Overlapping exceptions (socket.error and OSError are the same):HIGH
+overlapping-except:65:7::Overlapping exceptions (socket.error is an ancestor class of ConnectionError):HIGH
diff --git a/tests/functional/r/redefined_variable_type.py b/tests/functional/r/redefined_variable_type.py
new file mode 100644
index 000000000..aa89383d9
--- /dev/null
+++ b/tests/functional/r/redefined_variable_type.py
@@ -0,0 +1,85 @@
+"""Checks variable types aren't redefined within a method or a function"""
+
+# pylint: disable=too-few-public-methods,missing-docstring,unused-variable,invalid-name, useless-object-inheritance
+
+_OK = True
+
+class MyClass(object):
+
+ class Klass(object):
+ def __init__(self):
+ self.var2 = 'var'
+
+ def __init__(self):
+ self.var = True
+ self.var1 = 2
+ self.var2 = 1.
+ self.var1 = 2. # [redefined-variable-type]
+ self.a_str = "hello"
+ a_str = False
+ (a_str, b_str) = (1, 2) # no support for inference on tuple assignment
+ a_str = 2.0 if self.var else 1.0 # [redefined-variable-type]
+
+ def _getter(self):
+ return self.a_str
+ def _setter(self, val):
+ self.a_str = val
+ var2 = property(_getter, _setter)
+
+ def some_method(self):
+ def func():
+ var = 1
+ test = 'bar'
+ var = 'baz' # [redefined-variable-type]
+ self.var = 1 # the rule checks for redefinitions in the scope of a function or method
+ test = 'foo'
+ myint = 2
+ myint = False # [redefined-variable-type]
+
+_OK = "This is OK" # [redefined-variable-type]
+
+if _OK:
+ SOME_FLOAT = 1.
+
+def dummy_function():
+ return 2
+
+def other_function():
+ instance = MyClass()
+ instance = True # [redefined-variable-type]
+
+SOME_FLOAT = dummy_function() # [redefined-variable-type]
+
+A_GLOB = None
+A_GLOB = [1, 2, 3]
+
+def func2(x):
+ if x:
+ var = 'foo'
+ else:
+ var = True
+
+ if x:
+ var2 = 'foo'
+ elif not x:
+ var2 = 2
+ else:
+ pass
+
+ if x:
+ var3 = 'foo'
+ var3 = 2 # [redefined-variable-type]
+ else:
+ pass
+
+ var = 2 # [redefined-variable-type]
+
+ if x:
+ pass
+ elif not x:
+ var4 = True
+ elif _OK:
+ pass
+ else:
+ var4 = 2.
+ var4 = 'baz' # [redefined-variable-type]
diff --git a/tests/functional/r/redefined_variable_type.rc b/tests/functional/r/redefined_variable_type.rc
new file mode 100644
index 000000000..8ee18a8f1
--- /dev/null
+++ b/tests/functional/r/redefined_variable_type.rc
@@ -0,0 +1,2 @@
+[MASTER]
+load-plugins=pylint.extensions.redefined_variable_type,
diff --git a/tests/functional/r/redefined_variable_type.txt b/tests/functional/r/redefined_variable_type.txt
new file mode 100644
index 000000000..a0205c7aa
--- /dev/null
+++ b/tests/functional/r/redefined_variable_type.txt
@@ -0,0 +1,10 @@
+redefined-variable-type:17:8:MyClass.__init__:Redefinition of self.var1 type from int to float:HIGH
+redefined-variable-type:21:8:MyClass.__init__:Redefinition of a_str type from bool to float:HIGH
+redefined-variable-type:33:12:MyClass.some_method.func:Redefinition of var type from int to str:HIGH
+redefined-variable-type:37:8:MyClass.some_method:Redefinition of myint type from int to bool:HIGH
+redefined-variable-type:39:0::Redefinition of _OK type from bool to str:HIGH
+redefined-variable-type:49:4:other_function:Redefinition of instance type from functional.r.redefined_variable_type.MyClass to bool:HIGH
+redefined-variable-type:51:0::Redefinition of SOME_FLOAT type from float to int:HIGH
+redefined-variable-type:71:8:func2:Redefinition of var3 type from str to int:HIGH
+redefined-variable-type:75:4:func2:Redefinition of var type from bool to int:HIGH
+redefined-variable-type:85:8:func2:Redefinition of var4 type from float to str:HIGH