From 0a4169614daa0708abdfa05bcdd3ad670e3d94a1 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 1 Oct 2015 14:11:57 +0300 Subject: Update the list of special methods with the methods added in PEP 492. --- pylint/checkers/utils.py | 6 +++--- .../test/functional/unexpected_special_method_signature.py | 14 ++++++++++++++ .../functional/unexpected_special_method_signature.txt | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index dda5f44..443e32d 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -57,9 +57,9 @@ _SPECIAL_METHODS_PARAMS = { '__dir__', '__len__', '__length_hint__', '__iter__', '__reversed__', '__neg__', '__pos__', '__abs__', '__invert__', '__complex__', '__int__', '__float__', '__neg__', '__pos__', '__abs__', '__complex__', '__int__', - '__float__', '__index__', '__enter__', '__getnewargs_ex__', + '__float__', '__index__', '__enter__', '__aenter__', '__getnewargs_ex__', '__getnewargs__', '__getstate__', '__reduce__', '__copy__', - '__unicode__', '__nonzero__'), + '__unicode__', '__nonzero__', '__await__', '__aiter__', '__anext__'), 1: ('__format__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__getattr__', '__getattribute__', '__delattr__', @@ -77,7 +77,7 @@ _SPECIAL_METHODS_PARAMS = { 2: ('__setattr__', '__get__', '__set__', '__setitem__'), - 3: ('__exit__', ), + 3: ('__exit__', '__aexit__'), (0, 1): ('__round__', ), } diff --git a/pylint/test/functional/unexpected_special_method_signature.py b/pylint/test/functional/unexpected_special_method_signature.py index 8d96e48..41f02e5 100644 --- a/pylint/test/functional/unexpected_special_method_signature.py +++ b/pylint/test/functional/unexpected_special_method_signature.py @@ -52,6 +52,20 @@ class ThirdBadContextManager(object): pass +class Async(object): + + def __aiter__(self, extra): # [unexpected-special-method-signature] + pass + def __anext__(self, extra, argument): # [unexpected-special-method-signature] + pass + def __await__(self, param): # [unexpected-special-method-signature] + pass + def __aenter__(self, first): # [unexpected-special-method-signature] + pass + def __aexit__(self): # [unexpected-special-method-signature] + pass + + class Valid(object): def __new__(cls, test, multiple, args): diff --git a/pylint/test/functional/unexpected_special_method_signature.txt b/pylint/test/functional/unexpected_special_method_signature.txt index 521a02c..4fb52df 100644 --- a/pylint/test/functional/unexpected_special_method_signature.txt +++ b/pylint/test/functional/unexpected_special_method_signature.txt @@ -8,4 +8,9 @@ no-method-argument:26:Invalid.__iter__:Method has no argument unexpected-special-method-signature:30:Invalid.__getattr__:The special method '__getattr__' expects 1 param(s), 2 were given unexpected-special-method-signature:37:FirstBadContextManager.__exit__:The special method '__exit__' expects 3 param(s), 1 was given unexpected-special-method-signature:43:SecondBadContextManager.__exit__:The special method '__exit__' expects 3 param(s), 4 were given -unexpected-special-method-signature:51:ThirdBadContextManager.__exit__:The special method '__exit__' expects 3 param(s), 4 were given \ No newline at end of file +unexpected-special-method-signature:51:ThirdBadContextManager.__exit__:The special method '__exit__' expects 3 param(s), 4 were given +unexpected-special-method-signature:57:Async.__aiter__:The special method '__aiter__' expects 0 param(s), 1 was given +unexpected-special-method-signature:59:Async.__anext__:The special method '__anext__' expects 0 param(s), 2 were given +unexpected-special-method-signature:61:Async.__await__:The special method '__await__' expects 0 param(s), 1 was given +unexpected-special-method-signature:63:Async.__aenter__:The special method '__aenter__' expects 0 param(s), 1 was given +unexpected-special-method-signature:65:Async.__aexit__:The special method '__aexit__' expects 3 param(s), 0 was given \ No newline at end of file -- cgit v1.2.1