-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for alternative union syntax - PEP 604
- Loading branch information
1 parent
b6edb60
commit 1175b6e
Showing
11 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,79 @@ | ||
"""Test PEP 604 - Alternative Union syntax""" | ||
# pylint: disable=missing-function-docstring,unused-argument,invalid-name,missing-class-docstring,inherit-non-class,too-few-public-methods | ||
import dataclasses | ||
import typing | ||
from dataclasses import dataclass | ||
from typing import NamedTuple, TypedDict | ||
|
||
|
||
Alias = str | list[int] | ||
lst = [typing.Dict[str, int] | None,] | ||
|
||
cast_var = 1 | ||
cast_var = typing.cast(str | int, cast_var) | ||
|
||
T = typing.TypeVar("T", int | str, bool) | ||
|
||
(lambda x: 2)(int | str) | ||
|
||
var: str | int | ||
|
||
def func(arg: int | str): | ||
pass | ||
|
||
def func2() -> int | str: | ||
pass | ||
|
||
class CustomCls(int): | ||
pass | ||
|
||
Alias2 = CustomCls | str | ||
|
||
var2 = CustomCls(1) | int(2) | ||
|
||
|
||
# Check typing.NamedTuple | ||
CustomNamedTuple = typing.NamedTuple( | ||
"CustomNamedTuple", [("my_var", int | str)]) | ||
|
||
class CustomNamedTuple2(NamedTuple): | ||
my_var: int | str | ||
|
||
class CustomNamedTuple3(typing.NamedTuple): | ||
my_var: int | str | ||
|
||
|
||
# Check typing.TypedDict | ||
CustomTypedDict = TypedDict("CustomTypedDict", my_var=(int | str)) | ||
|
||
CustomTypedDict2 = TypedDict("CustomTypedDict2", {"my_var": int | str}) | ||
|
||
class CustomTypedDict3(TypedDict): | ||
my_var: int | str | ||
|
||
class CustomTypedDict4(typing.TypedDict): | ||
my_var: int | str | ||
|
||
|
||
# Check dataclasses | ||
def my_decorator(*args, **kwargs): | ||
def wraps(*args, **kwargs): | ||
pass | ||
return wraps | ||
|
||
@dataclass | ||
class CustomDataClass: | ||
my_var: int | str | ||
|
||
@dataclasses.dataclass | ||
class CustomDataClass2: | ||
my_var: int | str | ||
|
||
@dataclass() | ||
class CustomDataClass3: | ||
my_var: int | str | ||
|
||
@my_decorator | ||
@dataclasses.dataclass | ||
class CustomDataClass4: | ||
my_var: int | str |
This file contains 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,2 @@ | ||
[testoptions] | ||
min_pyver=3.10 |
This file contains 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,84 @@ | ||
"""Test PEP 604 - Alternative Union syntax | ||
without postponed evaluation of annotations. | ||
For Python 3.7 - 3.9: Everything should fail. | ||
Testing only 3.8/3.9 to support TypedDict. | ||
""" | ||
# pylint: disable=missing-function-docstring,unused-argument,invalid-name,missing-class-docstring,inherit-non-class,too-few-public-methods,line-too-long | ||
import dataclasses | ||
import typing | ||
from dataclasses import dataclass | ||
from typing import NamedTuple, TypedDict | ||
|
||
|
||
Alias = str | typing.List[int] # [unsupported-binary-operation] | ||
lst = [typing.Dict[str, int] | None,] # [unsupported-binary-operation] | ||
|
||
cast_var = 1 | ||
cast_var = typing.cast(str | int, cast_var) # [unsupported-binary-operation] | ||
|
||
T = typing.TypeVar("T", int | str, bool) # [unsupported-binary-operation] | ||
|
||
(lambda x: 2)(int | str) # [unsupported-binary-operation] | ||
|
||
var: str | int # [unsupported-binary-operation] | ||
|
||
def func(arg: int | str): # [unsupported-binary-operation] | ||
pass | ||
|
||
def func2() -> int | str: # [unsupported-binary-operation] | ||
pass | ||
|
||
class CustomCls(int): | ||
pass | ||
|
||
Alias2 = CustomCls | str # [unsupported-binary-operation] | ||
|
||
var2 = CustomCls(1) | int(2) | ||
|
||
|
||
# Check typing.NamedTuple | ||
CustomNamedTuple = typing.NamedTuple( | ||
"CustomNamedTuple", [("my_var", int | str)]) # [unsupported-binary-operation] | ||
|
||
class CustomNamedTuple2(NamedTuple): | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
class CustomNamedTuple3(typing.NamedTuple): | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
|
||
# Check typing.TypedDict | ||
CustomTypedDict = TypedDict("CustomTypedDict", my_var=int | str) # [unsupported-binary-operation] | ||
|
||
CustomTypedDict2 = TypedDict("CustomTypedDict2", {"my_var": int | str}) # [unsupported-binary-operation] | ||
|
||
class CustomTypedDict3(TypedDict): | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
class CustomTypedDict4(typing.TypedDict): | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
|
||
# Check dataclasses | ||
def my_decorator(*args, **kwargs): | ||
def wraps(*args, **kwargs): | ||
pass | ||
return wraps | ||
|
||
@dataclass | ||
class CustomDataClass: | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
@dataclasses.dataclass | ||
class CustomDataClass2: | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
@dataclass() | ||
class CustomDataClass3: | ||
my_var: int | str # [unsupported-binary-operation] | ||
|
||
@my_decorator | ||
@dataclasses.dataclass | ||
class CustomDataClass4: | ||
my_var: int | str # [unsupported-binary-operation] |
This file contains 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.10 |
This file contains 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 @@ | ||
unsupported-binary-operation:14:8::unsupported operand type(s) for | | ||
unsupported-binary-operation:15:7::unsupported operand type(s) for | | ||
unsupported-binary-operation:18:23::unsupported operand type(s) for | | ||
unsupported-binary-operation:20:24::unsupported operand type(s) for | | ||
unsupported-binary-operation:22:14::unsupported operand type(s) for | | ||
unsupported-binary-operation:24:5::unsupported operand type(s) for | | ||
unsupported-binary-operation:26:14:func:unsupported operand type(s) for | | ||
unsupported-binary-operation:29:15:func2:unsupported operand type(s) for | | ||
unsupported-binary-operation:35:9::unsupported operand type(s) for | | ||
unsupported-binary-operation:42:36::unsupported operand type(s) for | | ||
unsupported-binary-operation:45:12:CustomNamedTuple2:unsupported operand type(s) for | | ||
unsupported-binary-operation:48:12:CustomNamedTuple3:unsupported operand type(s) for | | ||
unsupported-binary-operation:52:54::unsupported operand type(s) for | | ||
unsupported-binary-operation:54:60::unsupported operand type(s) for | | ||
unsupported-binary-operation:57:12:CustomTypedDict3:unsupported operand type(s) for | | ||
unsupported-binary-operation:60:12:CustomTypedDict4:unsupported operand type(s) for | | ||
unsupported-binary-operation:71:12:CustomDataClass:unsupported operand type(s) for | | ||
unsupported-binary-operation:75:12:CustomDataClass2:unsupported operand type(s) for | | ||
unsupported-binary-operation:79:12:CustomDataClass3:unsupported operand type(s) for | | ||
unsupported-binary-operation:84:12:CustomDataClass4:unsupported operand type(s) for | |
This file contains 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 604 - Alternative Union syntax | ||
with postponed evaluation of annotations enabled. | ||
For Python 3.7 - 3.9: Most things should work. | ||
Testing only 3.8/3.9 to support TypedDict. | ||
""" | ||
# pylint: disable=missing-function-docstring,unused-argument,invalid-name,missing-class-docstring,inherit-non-class,too-few-public-methods,line-too-long | ||
from __future__ import annotations | ||
import dataclasses | ||
import typing | ||
from dataclasses import dataclass | ||
from typing import NamedTuple, TypedDict | ||
|
||
|
||
Alias = str | typing.List[int] # [unsupported-binary-operation] | ||
lst = [typing.Dict[str, int] | None,] # [unsupported-binary-operation] | ||
|
||
cast_var = 1 | ||
cast_var = typing.cast(str | int, cast_var) # [unsupported-binary-operation] | ||
|
||
T = typing.TypeVar("T", int | str, bool) # [unsupported-binary-operation] | ||
|
||
(lambda x: 2)(int | str) # [unsupported-binary-operation] | ||
|
||
var: str | int | ||
|
||
def func(arg: int | str): | ||
pass | ||
|
||
def func2() -> int | str: | ||
pass | ||
|
||
class CustomCls(int): | ||
pass | ||
|
||
Alias2 = CustomCls | str # [unsupported-binary-operation] | ||
|
||
var2 = CustomCls(1) | int(2) | ||
|
||
|
||
# Check typing.NamedTuple | ||
CustomNamedTuple = typing.NamedTuple( | ||
"CustomNamedTuple", [("my_var", int | str)]) # [unsupported-binary-operation] | ||
|
||
class CustomNamedTuple2(NamedTuple): | ||
my_var: int | str | ||
|
||
class CustomNamedTuple3(typing.NamedTuple): | ||
my_var: int | str | ||
|
||
|
||
# Check typing.TypedDict | ||
CustomTypedDict = TypedDict("CustomTypedDict", my_var=int | str) # [unsupported-binary-operation] | ||
|
||
CustomTypedDict2 = TypedDict("CustomTypedDict2", {"my_var": int | str}) # [unsupported-binary-operation] | ||
|
||
class CustomTypedDict3(TypedDict): | ||
my_var: int | str | ||
|
||
class CustomTypedDict4(typing.TypedDict): | ||
my_var: int | str | ||
|
||
|
||
# Check dataclasses | ||
def my_decorator(*args, **kwargs): | ||
def wraps(*args, **kwargs): | ||
pass | ||
return wraps | ||
|
||
@dataclass | ||
class CustomDataClass: | ||
my_var: int | str | ||
|
||
@dataclasses.dataclass | ||
class CustomDataClass2: | ||
my_var: int | str | ||
|
||
@dataclass() | ||
class CustomDataClass3: | ||
my_var: int | str | ||
|
||
@my_decorator | ||
@dataclasses.dataclass | ||
class CustomDataClass4: | ||
my_var: int | str |
This file contains 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.10 |
This file contains 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,9 @@ | ||
unsupported-binary-operation:15:8::unsupported operand type(s) for | | ||
unsupported-binary-operation:16:7::unsupported operand type(s) for | | ||
unsupported-binary-operation:19:23::unsupported operand type(s) for | | ||
unsupported-binary-operation:21:24::unsupported operand type(s) for | | ||
unsupported-binary-operation:23:14::unsupported operand type(s) for | | ||
unsupported-binary-operation:36:9::unsupported operand type(s) for | | ||
unsupported-binary-operation:43:36::unsupported operand type(s) for | | ||
unsupported-binary-operation:53:54::unsupported operand type(s) for | | ||
unsupported-binary-operation:55:60::unsupported operand type(s) for | |