diff --git a/tests/functional/a/arguments.py b/tests/functional/a/arguments.py index df92903453..e5e09cfef7 100644 --- a/tests/functional/a/arguments.py +++ b/tests/functional/a/arguments.py @@ -260,3 +260,13 @@ def func(one, two, three): CALL = lambda *args: func(*args) + + +# Check that typing.NewType calls expect exactly one argument +import typing + + +ChildType = typing.NewType("AliasType", int) +ChildType() # [no-value-for-parameter] +ChildType(1) +ChildType(1, 2) # [too-many-function-args] diff --git a/tests/functional/a/arguments.txt b/tests/functional/a/arguments.txt index 400be7454b..4d60edef49 100644 --- a/tests/functional/a/arguments.txt +++ b/tests/functional/a/arguments.txt @@ -37,3 +37,5 @@ unexpected-keyword-arg:202:23:202:56:namedtuple_replace_issue_1036:Unexpected ke no-value-for-parameter:215:0:215:24::No value for argument 'third' in function call:UNDEFINED no-value-for-parameter:216:0:216:30::No value for argument 'second' in function call:UNDEFINED unexpected-keyword-arg:217:0:217:43::Unexpected keyword argument 'fourth' in function call:UNDEFINED +no-value-for-parameter:270:0:270:11::No value for argument 'val' in constructor call:UNDEFINED +too-many-function-args:272:0:272:15::Too many positional arguments for constructor call:UNDEFINED diff --git a/tests/functional/i/iterable_context.py b/tests/functional/i/iterable_context.py index 2e32ac5f34..c984e7d210 100644 --- a/tests/functional/i/iterable_context.py +++ b/tests/functional/i/iterable_context.py @@ -4,6 +4,7 @@ """ # pylint: disable=missing-docstring,invalid-name,too-few-public-methods,no-self-use,import-error,unused-argument,bad-mcs-method-argument,wrong-import-position,no-else-return, useless-object-inheritance, unnecessary-comprehension,redundant-u-string-prefix from __future__ import print_function +import typing # primitives numbers = [1, 2, 3] @@ -192,5 +193,11 @@ def __getattr__(self, attr): pass +Subtype = typing.NewType("Subtype", typing.List[int]) + +for i in Subtype([1, 2, 3]): + pass + + # Regression test for https://github.com/PyCQA/pylint/issues/6372 string_twos = "".join(str(*y) for _, *y in [[1, 2], [1, 2]]) diff --git a/tests/functional/i/iterable_context.txt b/tests/functional/i/iterable_context.txt index ef59b379c7..4fa94f14f2 100644 --- a/tests/functional/i/iterable_context.txt +++ b/tests/functional/i/iterable_context.txt @@ -1,10 +1,10 @@ -not-an-iterable:58:9:58:22::Non-iterable value powers_of_two is used in an iterating context:UNDEFINED -not-an-iterable:93:6:93:9::Non-iterable value A() is used in an iterating context:UNDEFINED -not-an-iterable:95:6:95:7::Non-iterable value B is used in an iterating context:UNDEFINED -not-an-iterable:96:9:96:12::Non-iterable value A() is used in an iterating context:UNDEFINED -not-an-iterable:100:9:100:10::Non-iterable value B is used in an iterating context:UNDEFINED -not-an-iterable:103:9:103:14::Non-iterable value range is used in an iterating context:UNDEFINED -not-an-iterable:107:9:107:13::Non-iterable value True is used in an iterating context:UNDEFINED -not-an-iterable:110:9:110:13::Non-iterable value None is used in an iterating context:UNDEFINED -not-an-iterable:113:9:113:12::Non-iterable value 8.5 is used in an iterating context:UNDEFINED -not-an-iterable:116:9:116:11::Non-iterable value 10 is used in an iterating context:UNDEFINED +not-an-iterable:59:9:59:22::Non-iterable value powers_of_two is used in an iterating context:UNDEFINED +not-an-iterable:94:6:94:9::Non-iterable value A() is used in an iterating context:UNDEFINED +not-an-iterable:96:6:96:7::Non-iterable value B is used in an iterating context:UNDEFINED +not-an-iterable:97:9:97:12::Non-iterable value A() is used in an iterating context:UNDEFINED +not-an-iterable:101:9:101:10::Non-iterable value B is used in an iterating context:UNDEFINED +not-an-iterable:104:9:104:14::Non-iterable value range is used in an iterating context:UNDEFINED +not-an-iterable:108:9:108:13::Non-iterable value True is used in an iterating context:UNDEFINED +not-an-iterable:111:9:111:13::Non-iterable value None is used in an iterating context:UNDEFINED +not-an-iterable:114:9:114:12::Non-iterable value 8.5 is used in an iterating context:UNDEFINED +not-an-iterable:117:9:117:11::Non-iterable value 10 is used in an iterating context:UNDEFINED diff --git a/tests/functional/m/member/member_checks.py b/tests/functional/m/member/member_checks.py index c1b6a22fba..562a85ed84 100644 --- a/tests/functional/m/member/member_checks.py +++ b/tests/functional/m/member/member_checks.py @@ -231,3 +231,44 @@ class Animal(Enum): print(keyy) for vall in Animal.__members__.values(): print(vall) + + +# Test for false positives on NewType classes +from typing import NewType + +UserId = NewType("UserId", str) + +some_id = UserId("id") +some_id.capitalize() +some_id.not_a_str_method() # [no-member] + + +class BaseClass: + def __init__(self, value): + self.value = value + + +ChildClass = NewType("ChildClass", BaseClass) + + +base = BaseClass(5) +base.value +base.bad_attr # [no-member] + + +child = ChildClass(base) +child.value +child.bad_attr # [no-member] + + +import pathlib + +PathChild = NewType("PathChild", pathlib.PurePath) + +path = pathlib.PurePath("/") +path.root +path.bad_attr # [no-member] + +path_child = PathChild(path) +path_child.root +path_child.bad_attr # [no-member] diff --git a/tests/functional/m/member/member_checks.txt b/tests/functional/m/member/member_checks.txt index 22eed257f9..64f697721b 100644 --- a/tests/functional/m/member/member_checks.txt +++ b/tests/functional/m/member/member_checks.txt @@ -17,3 +17,8 @@ no-member:135:0:135:18::Class 'str' has no 'portocala' member:INFERENCE no-member:170:19:170:32:NoDunderNameInInstance.__init__:Instance of 'NoDunderNameInInstance' has no '__name__' member:INFERENCE no-member:176:14:176:23:InvalidAccessBySlots.__init__:Instance of 'InvalidAccessBySlots' has no 'teta' member:INFERENCE no-member:208:13:208:20::Class 'Cls' has no 'BAZ' member; maybe 'BAR'?:INFERENCE +no-member:243:0:243:24::Instance of 'UserId' has no 'not_a_str_method' member:INFERENCE +no-member:256:0:256:13::Instance of 'BaseClass' has no 'bad_attr' member:INFERENCE +no-member:261:0:261:14::Instance of 'ChildClass' has no 'bad_attr' member:INFERENCE +no-member:270:0:270:13::Instance of 'PurePath' has no 'bad_attr' member:INFERENCE +no-member:274:0:274:19::Instance of 'PathChild' has no 'bad_attr' member:INFERENCE