summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/i/invalid/m/invalid_metaclass.py32
-rw-r--r--tests/functional/i/invalid/m/invalid_metaclass.txt6
-rw-r--r--tests/functional/n/not_callable.py57
-rw-r--r--tests/functional/n/not_callable.txt19
-rw-r--r--tests/functional/u/unsubscriptable_object.py7
5 files changed, 111 insertions, 10 deletions
diff --git a/tests/functional/i/invalid/m/invalid_metaclass.py b/tests/functional/i/invalid/m/invalid_metaclass.py
index c0e9d74be..ec251e47d 100644
--- a/tests/functional/i/invalid/m/invalid_metaclass.py
+++ b/tests/functional/i/invalid/m/invalid_metaclass.py
@@ -32,3 +32,35 @@ class ThirdGood(object):
@six.add_metaclass(ValidAsMetaclass)
class FourthGood(object):
pass
+
+
+class FirstInvalid(object, metaclass=int): # [invalid-metaclass]
+ pass
+
+
+class SecondInvalid(object, metaclass=InvalidAsMetaclass): # [invalid-metaclass]
+ pass
+
+
+class ThirdInvalid(object, metaclass=2): # [invalid-metaclass]
+ pass
+
+
+class FourthInvalid(object, metaclass=InvalidAsMetaclass()): # [invalid-metaclass]
+ pass
+
+
+def invalid_metaclass_1(name, bases, attrs):
+ return int
+
+
+def invalid_metaclass_2(name, bases, attrs):
+ return 1
+
+
+class Invalid(metaclass=invalid_metaclass_1): # [invalid-metaclass]
+ pass
+
+
+class InvalidSecond(metaclass=invalid_metaclass_2): # [invalid-metaclass]
+ pass
diff --git a/tests/functional/i/invalid/m/invalid_metaclass.txt b/tests/functional/i/invalid/m/invalid_metaclass.txt
new file mode 100644
index 000000000..c5ca48d76
--- /dev/null
+++ b/tests/functional/i/invalid/m/invalid_metaclass.txt
@@ -0,0 +1,6 @@
+invalid-metaclass:37:0:38:8:FirstInvalid:Invalid metaclass 'int' used:UNDEFINED
+invalid-metaclass:41:0:42:8:SecondInvalid:Invalid metaclass 'InvalidAsMetaclass' used:UNDEFINED
+invalid-metaclass:45:0:46:8:ThirdInvalid:Invalid metaclass '2' used:UNDEFINED
+invalid-metaclass:49:0:50:8:FourthInvalid:Invalid metaclass 'Instance of invalid_metaclass.InvalidAsMetaclass' used:UNDEFINED
+invalid-metaclass:61:0:62:8:Invalid:Invalid metaclass 'int' used:UNDEFINED
+invalid-metaclass:65:0:66:8:InvalidSecond:Invalid metaclass '1' used:UNDEFINED
diff --git a/tests/functional/n/not_callable.py b/tests/functional/n/not_callable.py
index 7c361aa6a..38232dc46 100644
--- a/tests/functional/n/not_callable.py
+++ b/tests/functional/n/not_callable.py
@@ -1,4 +1,5 @@
# pylint: disable=missing-docstring,no-self-use,too-few-public-methods,wrong-import-position,useless-object-inheritance,use-dict-literal
+# pylint: disable=wrong-import-order, undefined-variable
REVISION = None
@@ -117,7 +118,8 @@ PROP1.instance()
PROP1.does_not_make_sense()
-import missing # pylint: disable=import-error
+import missing # pylint: disable=import-error
+
class UnknownBaseCallable(missing.Blah):
pass
@@ -133,3 +135,56 @@ class ClassWithProperty:
return 42
CLASS_WITH_PROP = ClassWithProperty().value() # [not-callable]
+
+# Test typing.Namedtuple not callable
+# See: https://github.com/PyCQA/pylint/issues/1295
+import typing
+
+Named = typing.NamedTuple("Named", [("foo", int), ("bar", int)])
+named = Named(1, 2)
+
+# Test descriptor call
+def func():
+ pass
+
+
+class ADescriptor:
+ def __get__(self, instance, owner):
+ return func
+
+
+class AggregateCls:
+ a = ADescriptor()
+
+
+AggregateCls().a()
+
+
+# Make sure not-callable isn't raised for descriptors
+
+# astroid can't process descriptors correctly so
+# pylint needs to ignore not-callable for them
+# right now
+
+# Test for https://github.com/PyCQA/pylint/issues/1699
+
+import multiprocessing
+
+multiprocessing.current_process()
+
+# Make sure not-callable isn't raised for uninferable properties
+class MyClass:
+ @property
+ def call(self):
+ return undefined
+
+
+a = A()
+a.call()
+
+# Make sure the callable check does not crash when a node's parent cannot be determined.
+def get_number(arg):
+ return 2 * arg
+
+
+get_number(10)() # [not-callable]
diff --git a/tests/functional/n/not_callable.txt b/tests/functional/n/not_callable.txt
index a7066e5b2..f079bbfe8 100644
--- a/tests/functional/n/not_callable.txt
+++ b/tests/functional/n/not_callable.txt
@@ -1,9 +1,10 @@
-not-callable:5:0:5:10::REVISION is not callable:UNDEFINED
-not-callable:23:12:23:22::INSTANCE is not callable:UNDEFINED
-not-callable:25:12:25:18::LIST is not callable:UNDEFINED
-not-callable:27:12:27:18::DICT is not callable:UNDEFINED
-not-callable:29:12:29:19::TUPLE is not callable:UNDEFINED
-not-callable:31:12:31:17::INT is not callable:UNDEFINED
-not-callable:66:0:66:13::PROP.test is not callable:UNDEFINED
-not-callable:67:0:67:13::PROP.custom is not callable:UNDEFINED
-not-callable:135:18:135:45::ClassWithProperty().value is not callable:UNDEFINED
+not-callable:6:0:6:10::REVISION is not callable:UNDEFINED
+not-callable:24:12:24:22::INSTANCE is not callable:UNDEFINED
+not-callable:26:12:26:18::LIST is not callable:UNDEFINED
+not-callable:28:12:28:18::DICT is not callable:UNDEFINED
+not-callable:30:12:30:19::TUPLE is not callable:UNDEFINED
+not-callable:32:12:32:17::INT is not callable:UNDEFINED
+not-callable:67:0:67:13::PROP.test is not callable:UNDEFINED
+not-callable:68:0:68:13::PROP.custom is not callable:UNDEFINED
+not-callable:137:18:137:45::ClassWithProperty().value is not callable:UNDEFINED
+not-callable:190:0:190:16::get_number(10) is not callable:UNDEFINED
diff --git a/tests/functional/u/unsubscriptable_object.py b/tests/functional/u/unsubscriptable_object.py
new file mode 100644
index 000000000..0b7da78b3
--- /dev/null
+++ b/tests/functional/u/unsubscriptable_object.py
@@ -0,0 +1,7 @@
+"""Tests for unscubscriptable-object"""
+
+# Test for typing.NamedTuple
+# See: https://github.com/PyCQA/pylint/issues/1295
+import typing
+
+MyType = typing.Tuple[str, str]