diff options
author | Pascal Corpet <pcorpet@users.noreply.github.com> | 2019-02-04 14:56:09 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-02-04 14:56:09 +0100 |
commit | 03b4d035203c750908e197debdbb3f8161d51666 (patch) | |
tree | fa76e6994b2c001d369d03ccaa6e441d0737b402 /pylint/test/functional | |
parent | c2af5c760307edaf50cc519d189b620ba41f12db (diff) | |
download | pylint-git-03b4d035203c750908e197debdbb3f8161d51666.tar.gz |
Take into account `__class_getitem__`
Take into account `__class_getitem__` from PEP 560 and fixes some false
positives for `no-self-argument` and `unsubscriptable-object`
PEP: https://www.python.org/dev/peps/pep-0560/
Close #2416
Diffstat (limited to 'pylint/test/functional')
6 files changed, 40 insertions, 0 deletions
diff --git a/pylint/test/functional/no_self_argument_py37.py b/pylint/test/functional/no_self_argument_py37.py new file mode 100644 index 000000000..8e6d6fc34 --- /dev/null +++ b/pylint/test/functional/no_self_argument_py37.py @@ -0,0 +1,15 @@ +"""Test detection of self as argument of first method in Python 3.7 and above.""" + +# pylint: disable=missing-docstring,too-few-public-methods,useless-object-inheritance + + +class Toto(object): + + def __class_getitem__(cls, params): + # This is actually a special method which is always a class method. + # See https://www.python.org/dev/peps/pep-0560/#class-getitem + pass + + def __class_other__(cls, params): # [no-self-argument] + # This is not a special case and as such is an instance method. + pass diff --git a/pylint/test/functional/no_self_argument_py37.rc b/pylint/test/functional/no_self_argument_py37.rc new file mode 100644 index 000000000..a17bb22da --- /dev/null +++ b/pylint/test/functional/no_self_argument_py37.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7 diff --git a/pylint/test/functional/no_self_argument_py37.txt b/pylint/test/functional/no_self_argument_py37.txt new file mode 100644 index 000000000..812b8aa0c --- /dev/null +++ b/pylint/test/functional/no_self_argument_py37.txt @@ -0,0 +1 @@ +no-self-argument:13:Toto.__class_other__:Method should have "self" as first argument diff --git a/pylint/test/functional/unsubscriptable_value_py37.py b/pylint/test/functional/unsubscriptable_value_py37.py new file mode 100644 index 000000000..c7b06cfb2 --- /dev/null +++ b/pylint/test/functional/unsubscriptable_value_py37.py @@ -0,0 +1,19 @@ +""" +Checks that class used in a subscript supports subscription +(i.e. defines __class_getitem__ method). +""" +# pylint: disable=missing-docstring,pointless-statement,expression-not-assigned,wrong-import-position +# pylint: disable=too-few-public-methods,import-error,invalid-name,wrong-import-order, useless-object-inheritance + +import typing + +class Subscriptable(object): + + def __class_getitem__(cls, params): + pass + + +Subscriptable[0] +Subscriptable()[0] # [unsubscriptable-object] + +a: typing.List[int] diff --git a/pylint/test/functional/unsubscriptable_value_py37.rc b/pylint/test/functional/unsubscriptable_value_py37.rc new file mode 100644 index 000000000..a17bb22da --- /dev/null +++ b/pylint/test/functional/unsubscriptable_value_py37.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7 diff --git a/pylint/test/functional/unsubscriptable_value_py37.txt b/pylint/test/functional/unsubscriptable_value_py37.txt new file mode 100644 index 000000000..b2ff0fff5 --- /dev/null +++ b/pylint/test/functional/unsubscriptable_value_py37.txt @@ -0,0 +1 @@ +unsubscriptable-object:17::Value 'Subscriptable()' is unsubscriptable |