-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for pep585 with postponed evaluation #4059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pierre-Sassoulas
merged 1 commit into
pylint-dev:master
from
cdce8p:pep585-postponed-evaluation
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""Test PEP 585 in combination with postponed evaluation PEP 563. | ||
|
||
This check requires Python 3.7 or 3.8! | ||
Testing with 3.8 only, to support TypedDict. | ||
""" | ||
# pylint: disable=missing-docstring,unused-argument,unused-import,too-few-public-methods,invalid-name,inherit-non-class | ||
from __future__ import annotations | ||
import collections | ||
import dataclasses | ||
import typing | ||
from typing import NamedTuple, TypedDict | ||
from dataclasses import dataclass | ||
|
||
|
||
AliasInvalid = list[int] # [unsubscriptable-object] | ||
|
||
class CustomIntList(typing.List[int]): | ||
pass | ||
|
||
class CustomIntListError(list[int]): # [unsubscriptable-object] | ||
pass | ||
|
||
cast_variable = [1, 2, 3] | ||
cast_variable = typing.cast(list[int], cast_variable) # [unsubscriptable-object] | ||
|
||
T = typing.TypeVar("T", list[int], str) # [unsubscriptable-object] | ||
|
||
(lambda x: 2)(list[int]) # [unsubscriptable-object] | ||
|
||
|
||
# Check typing.NamedTuple | ||
CustomNamedTuple = typing.NamedTuple( | ||
"CustomNamedTuple", [("my_var", list[int])]) # [unsubscriptable-object] | ||
|
||
class CustomNamedTuple2(NamedTuple): | ||
my_var: list[int] | ||
|
||
class CustomNamedTuple3(typing.NamedTuple): | ||
my_var: list[int] | ||
|
||
|
||
# Check typing.TypedDict | ||
CustomTypedDict = TypedDict("CustomTypedDict", my_var=list[int]) # [unsubscriptable-object] | ||
|
||
CustomTypedDict2 = TypedDict("CustomTypedDict2", {"my_var": list[int]}) # [unsubscriptable-object] | ||
|
||
class CustomTypedDict3(TypedDict): | ||
my_var: list[int] | ||
|
||
class CustomTypedDict4(typing.TypedDict): | ||
my_var: list[int] | ||
|
||
|
||
# Check dataclasses | ||
def my_decorator(*args, **kwargs): | ||
def wraps(*args, **kwargs): | ||
pass | ||
return wraps | ||
|
||
@dataclass | ||
class CustomDataClass: | ||
my_var: list[int] | ||
|
||
@dataclasses.dataclass | ||
class CustomDataClass2: | ||
my_var: list[int] | ||
|
||
@dataclass() | ||
class CustomDataClass3: | ||
my_var: list[int] | ||
|
||
@my_decorator | ||
@dataclasses.dataclass | ||
class CustomDataClass4: | ||
my_var: list[int] | ||
|
||
|
||
# Allowed use cases | ||
var1: set[int] | ||
var2: collections.OrderedDict[str, int] | ||
|
||
def func(arg: list[int]): | ||
pass | ||
|
||
def func2() -> list[int]: | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[testoptions] | ||
min_pyver=3.8 | ||
max_pyver=3.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
unsubscriptable-object:15:15::Value 'list' is unsubscriptable | ||
unsubscriptable-object:20:25:CustomIntListError:Value 'list' is unsubscriptable | ||
unsubscriptable-object:24:28::Value 'list' is unsubscriptable | ||
unsubscriptable-object:26:24::Value 'list' is unsubscriptable | ||
unsubscriptable-object:28:14::Value 'list' is unsubscriptable | ||
unsubscriptable-object:33:36::Value 'list' is unsubscriptable | ||
unsubscriptable-object:43:54::Value 'list' is unsubscriptable | ||
unsubscriptable-object:45:60::Value 'list' is unsubscriptable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""Test PEP 585 without postponed evaluation. Everything should fail. | ||
|
||
This check requires Python 3.7 or Python 3.8! | ||
Testing with 3.8 only, to support TypedDict. | ||
""" | ||
# pylint: disable=missing-docstring,unused-argument,unused-import,too-few-public-methods,invalid-name,inherit-non-class | ||
import collections | ||
import dataclasses | ||
import typing | ||
from typing import NamedTuple, TypedDict | ||
from dataclasses import dataclass | ||
|
||
|
||
AliasInvalid = list[int] # [unsubscriptable-object] | ||
|
||
class CustomIntList(typing.List[int]): | ||
pass | ||
|
||
class CustomIntListError(list[int]): # [unsubscriptable-object] | ||
pass | ||
|
||
cast_variable = [1, 2, 3] | ||
cast_variable = typing.cast(list[int], cast_variable) # [unsubscriptable-object] | ||
|
||
T = typing.TypeVar("T", list[int], str) # [unsubscriptable-object] | ||
|
||
(lambda x: 2)(list[int]) # [unsubscriptable-object] | ||
|
||
|
||
# Check typing.NamedTuple | ||
CustomNamedTuple = typing.NamedTuple( | ||
"CustomNamedTuple", [("my_var", list[int])]) # [unsubscriptable-object] | ||
|
||
class CustomNamedTuple2(NamedTuple): | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
class CustomNamedTuple3(typing.NamedTuple): | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
|
||
# Check typing.TypedDict | ||
CustomTypedDict = TypedDict("CustomTypedDict", my_var=list[int]) # [unsubscriptable-object] | ||
|
||
CustomTypedDict2 = TypedDict("CustomTypedDict2", {"my_var": list[int]}) # [unsubscriptable-object] | ||
|
||
class CustomTypedDict3(TypedDict): | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
class CustomTypedDict4(typing.TypedDict): | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
|
||
# Check dataclasses | ||
def my_decorator(*args, **kwargs): | ||
def wraps(*args, **kwargs): | ||
pass | ||
return wraps | ||
|
||
@dataclass | ||
class CustomDataClass: | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
@dataclasses.dataclass | ||
class CustomDataClass2: | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
@dataclass() | ||
class CustomDataClass3: | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
@my_decorator | ||
@dataclasses.dataclass | ||
class CustomDataClass4: | ||
my_var: list[int] # [unsubscriptable-object] | ||
|
||
|
||
|
||
var1: set[int] # [unsubscriptable-object] | ||
var2: collections.OrderedDict[str, int] # [unsubscriptable-object] | ||
|
||
def func(arg: list[int]): # [unsubscriptable-object] | ||
pass | ||
|
||
def func2() -> list[int]: # [unsubscriptable-object] | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[testoptions] | ||
min_pyver=3.8 | ||
max_pyver=3.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
unsubscriptable-object:14:15::Value 'list' is unsubscriptable | ||
unsubscriptable-object:19:25:CustomIntListError:Value 'list' is unsubscriptable | ||
unsubscriptable-object:23:28::Value 'list' is unsubscriptable | ||
unsubscriptable-object:25:24::Value 'list' is unsubscriptable | ||
unsubscriptable-object:27:14::Value 'list' is unsubscriptable | ||
unsubscriptable-object:32:36::Value 'list' is unsubscriptable | ||
unsubscriptable-object:35:12:CustomNamedTuple2:Value 'list' is unsubscriptable | ||
unsubscriptable-object:38:12:CustomNamedTuple3:Value 'list' is unsubscriptable | ||
unsubscriptable-object:42:54::Value 'list' is unsubscriptable | ||
unsubscriptable-object:44:60::Value 'list' is unsubscriptable | ||
unsubscriptable-object:47:12:CustomTypedDict3:Value 'list' is unsubscriptable | ||
unsubscriptable-object:50:12:CustomTypedDict4:Value 'list' is unsubscriptable | ||
unsubscriptable-object:61:12:CustomDataClass:Value 'list' is unsubscriptable | ||
unsubscriptable-object:65:12:CustomDataClass2:Value 'list' is unsubscriptable | ||
unsubscriptable-object:69:12:CustomDataClass3:Value 'list' is unsubscriptable | ||
unsubscriptable-object:74:12:CustomDataClass4:Value 'list' is unsubscriptable | ||
unsubscriptable-object:78:6::Value 'set' is unsubscriptable | ||
unsubscriptable-object:79:6::Value 'collections.OrderedDict' is unsubscriptable | ||
unsubscriptable-object:81:14:func:Value 'list' is unsubscriptable | ||
unsubscriptable-object:84:15:func2:Value 'list' is unsubscriptable |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.