diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2022-05-07 18:48:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 18:48:47 +0200 |
commit | cd5556f552ddc8b4babeb19e881ed52928697866 (patch) | |
tree | 444a538cb97b901788c5c492037819d28e464460 /tests/functional/g | |
parent | 257dcd5c4592098e5a5a407ce11fa6574ee29779 (diff) | |
download | pylint-git-cd5556f552ddc8b4babeb19e881ed52928697866.tar.gz |
Don't emit unsubscriptable-object for string annotations (#6536)
Diffstat (limited to 'tests/functional/g')
4 files changed, 27 insertions, 6 deletions
diff --git a/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.py b/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.py index 5ded73b3d..02cbcf081 100644 --- a/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.py +++ b/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.py @@ -4,7 +4,7 @@ In type annotation context, they can be used with postponed evaluation enabled, starting with PY37. """ # flake8: noqa -# pylint: disable=missing-docstring,pointless-statement +# pylint: disable=missing-docstring,pointless-statement,invalid-name # pylint: disable=too-few-public-methods,multiple-statements,line-too-long from __future__ import annotations @@ -172,8 +172,18 @@ var_re_Match: re.Match[str] # unsubscriptable types var_abc_Hashable: collections.abc.Hashable var_abc_Sized: collections.abc.Sized -var_abc_Hashable2: collections.abc.Hashable[int] # [unsubscriptable-object] -var_abc_Sized2: collections.abc.Sized[int] # [unsubscriptable-object] +var_abc_Hashable2: collections.abc.Hashable[int] # string annotations aren't checked +var_abc_Sized2: collections.abc.Sized[int] # string annotations aren't checked # subscriptable with Python 3.9 var_abc_ByteString: collections.abc.ByteString[int] + + +# Generic in type stubs only -> string annotations aren't checked +class A: + ... + +var_a1: A[str] # string annotations aren't checked +var_a2: "A[str]" # string annotations aren't checked +class B(A[str]): # [unsubscriptable-object] + ... diff --git a/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.txt b/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.txt index 56eca5192..d481f7ac6 100644 --- a/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.txt +++ b/tests/functional/g/generic_alias/generic_alias_postponed_evaluation_py37.txt @@ -52,5 +52,4 @@ abstract-method:107:0:107:21:DerivedMultiple:Method '__len__' is abstract in cla abstract-method:112:0:112:24:CustomAbstractCls2:Method '__len__' is abstract in class 'Sized' but is not overridden:UNDEFINED unsubscriptable-object:112:48:112:72:CustomAbstractCls2:Value 'collections.abc.Iterable' is unsubscriptable:UNDEFINED abstract-method:114:0:114:26:CustomImplementation:Method '__len__' is abstract in class 'Sized' but is not overridden:UNDEFINED -unsubscriptable-object:175:19:175:43::Value 'collections.abc.Hashable' is unsubscriptable:UNDEFINED -unsubscriptable-object:176:16:176:37::Value 'collections.abc.Sized' is unsubscriptable:UNDEFINED +unsubscriptable-object:188:8:188:9:B:Value 'A' is unsubscriptable:UNDEFINED diff --git a/tests/functional/g/generic_alias/generic_alias_typing.py b/tests/functional/g/generic_alias/generic_alias_typing.py index 6d114739a..4b9a98a0d 100644 --- a/tests/functional/g/generic_alias/generic_alias_typing.py +++ b/tests/functional/g/generic_alias/generic_alias_typing.py @@ -1,6 +1,6 @@ """Test generic alias support for typing.py types.""" # flake8: noqa -# pylint: disable=missing-docstring,pointless-statement +# pylint: disable=missing-docstring,pointless-statement,invalid-name # pylint: disable=too-few-public-methods,multiple-statements,line-too-long, unnecessary-dunder-call import abc import typing @@ -139,3 +139,13 @@ var_int: int[int] # [unsubscriptable-object] var_bytestring2: typing.ByteString[int] # [unsubscriptable-object] var_hashable2: typing.Hashable[int] # [unsubscriptable-object] var_sized2: typing.Sized[int] # [unsubscriptable-object] + + +# Generic in type stubs only -> string annotations aren't checked +class A: + ... + +var_a1: A[str] # [unsubscriptable-object] +var_a2: "A[str]" # string annotations aren't checked +class B(A[str]): # [unsubscriptable-object] + ... diff --git a/tests/functional/g/generic_alias/generic_alias_typing.txt b/tests/functional/g/generic_alias/generic_alias_typing.txt index 8ed10fe10..f33f49f91 100644 --- a/tests/functional/g/generic_alias/generic_alias_typing.txt +++ b/tests/functional/g/generic_alias/generic_alias_typing.txt @@ -17,3 +17,5 @@ unsubscriptable-object:138:9:138:12::Value 'int' is unsubscriptable:UNDEFINED unsubscriptable-object:139:17:139:34::Value 'typing.ByteString' is unsubscriptable:UNDEFINED unsubscriptable-object:140:15:140:30::Value 'typing.Hashable' is unsubscriptable:UNDEFINED unsubscriptable-object:141:12:141:24::Value 'typing.Sized' is unsubscriptable:UNDEFINED +unsubscriptable-object:148:8:148:9::Value 'A' is unsubscriptable:UNDEFINED +unsubscriptable-object:150:8:150:9:B:Value 'A' is unsubscriptable:UNDEFINED |