summaryrefslogtreecommitdiff
path: root/pylint/test/functional/redefined_variable_type.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/test/functional/redefined_variable_type.py')
-rw-r--r--pylint/test/functional/redefined_variable_type.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/pylint/test/functional/redefined_variable_type.py b/pylint/test/functional/redefined_variable_type.py
new file mode 100644
index 0000000..9851702
--- /dev/null
+++ b/pylint/test/functional/redefined_variable_type.py
@@ -0,0 +1,50 @@
+"""Checks variable types aren't redefined within a method or a function"""
+
+# pylint: disable=too-few-public-methods, missing-docstring, unused-variable
+
+_OK = True
+
+def my_func():
+ var = 'foo'
+ var = 'bar'
+ var = var.split() # [redefined-variable-type]
+
+class MyClass(object):
+ 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)
+ a_str = 2.0 if self.var else 1.0
+
+ def _getter(self):
+ return self.a_str
+ def _setter(self, val):
+ self.a_str = val
+ var2 = property(_getter, _setter)
+
+ def some_method(self):
+ self.var = 1
+ test = 'foo'
+ myint = 2
+ myint = False # [redefined-variable-type]
+
+_OK = "This is OK" # [redefined-variable-type]
+
+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]
+