diff options
Diffstat (limited to 'tests')
8 files changed, 285 insertions, 0 deletions
diff --git a/tests/functional/a/alternative_union_syntax.py b/tests/functional/a/alternative_union_syntax.py new file mode 100644 index 000000000..175e5a9ba --- /dev/null +++ b/tests/functional/a/alternative_union_syntax.py @@ -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 diff --git a/tests/functional/a/alternative_union_syntax.rc b/tests/functional/a/alternative_union_syntax.rc new file mode 100644 index 000000000..68a8c8ef1 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.10 diff --git a/tests/functional/a/alternative_union_syntax_error.py b/tests/functional/a/alternative_union_syntax_error.py new file mode 100644 index 000000000..54f9f8f52 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_error.py @@ -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] diff --git a/tests/functional/a/alternative_union_syntax_error.rc b/tests/functional/a/alternative_union_syntax_error.rc new file mode 100644 index 000000000..776b99f68 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_error.rc @@ -0,0 +1,3 @@ +[testoptions] +min_pyver=3.8 +max_pyver=3.10 diff --git a/tests/functional/a/alternative_union_syntax_error.txt b/tests/functional/a/alternative_union_syntax_error.txt new file mode 100644 index 000000000..2149b3285 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_error.txt @@ -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 | diff --git a/tests/functional/a/alternative_union_syntax_py37.py b/tests/functional/a/alternative_union_syntax_py37.py new file mode 100644 index 000000000..79bc28fc4 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_py37.py @@ -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 diff --git a/tests/functional/a/alternative_union_syntax_py37.rc b/tests/functional/a/alternative_union_syntax_py37.rc new file mode 100644 index 000000000..776b99f68 --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_py37.rc @@ -0,0 +1,3 @@ +[testoptions] +min_pyver=3.8 +max_pyver=3.10 diff --git a/tests/functional/a/alternative_union_syntax_py37.txt b/tests/functional/a/alternative_union_syntax_py37.txt new file mode 100644 index 000000000..c7172808e --- /dev/null +++ b/tests/functional/a/alternative_union_syntax_py37.txt @@ -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 | |