Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ reveal_type(f(n)) # N: Revealed type is "def (builtins.int, builtins.bytes) ->
[builtins fixtures/paramspec.pyi]

[case testParamSpecConcatenateNamedArgs]
# flags: --strict-concatenate
# flags: --python-version 3.8 --strict-concatenate
# this is one noticeable deviation from PEP but I believe it is for the better
from typing_extensions import ParamSpec, Concatenate
from typing import Callable, TypeVar
Expand Down Expand Up @@ -601,6 +601,8 @@ main:17: error: Incompatible return value type (got "Callable[[Arg(int, 'x'), **
main:17: note: This may be because "result" has arguments named: "x"

[case testNonStrictParamSpecConcatenateNamedArgs]
# flags: --python-version 3.8

# this is one noticeable deviation from PEP but I believe it is for the better
from typing_extensions import ParamSpec, Concatenate
from typing import Callable, TypeVar
Expand Down Expand Up @@ -644,6 +646,8 @@ reveal_type(n(42)) # N: Revealed type is "None"
[builtins fixtures/paramspec.pyi]

[case testCallablesAsParameters]
# flags: --python-version 3.8

# credits to https://github.com/microsoft/pyright/issues/2705
from typing_extensions import ParamSpec, Concatenate
from typing import Generic, Callable, Any
Expand All @@ -663,7 +667,7 @@ bar(abc)
[out]
main:11: error: invalid syntax
[out version>=3.8]
main:14: note: Revealed type is "__main__.Foo[[builtins.int, b: builtins.str]]"
main:16: note: Revealed type is "__main__.Foo[[builtins.int, b: builtins.str]]"

[case testSolveParamSpecWithSelfType]
from typing_extensions import ParamSpec, Concatenate
Expand Down
17 changes: 16 additions & 1 deletion test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,33 @@ def g(x: int): ...
) # type: ignore # E: Unused "type: ignore" comment

[case testPEP570ArgTypesMissing]
# flags: --disallow-untyped-defs
# flags: --python-version 3.8 --disallow-untyped-defs
def f(arg, /) -> None: ... # E: Function is missing a type annotation for one or more arguments

[case testPEP570ArgTypesBadDefault]
# flags: --python-version 3.8
def f(arg: int = "ERROR", /) -> None: ... # E: Incompatible default for argument "arg" (default has type "str", argument has type "int")

[case testPEP570ArgTypesDefault]
# flags: --python-version 3.8
def f(arg: int = 0, /) -> None:
reveal_type(arg) # N: Revealed type is "builtins.int"

[case testPEP570ArgTypesRequired]
# flags: --python-version 3.8
def f(arg: int, /) -> None:
reveal_type(arg) # N: Revealed type is "builtins.int"

[case testPEP570Required]
# flags: --python-version 3.8
def f(arg: int, /) -> None: ... # N: "f" defined here
f(1)
f("ERROR") # E: Argument 1 to "f" has incompatible type "str"; expected "int"
f(arg=1) # E: Unexpected keyword argument "arg" for "f"
f(arg="ERROR") # E: Unexpected keyword argument "arg" for "f"

[case testPEP570Default]
# flags: --python-version 3.8
def f(arg: int = 0, /) -> None: ... # N: "f" defined here
f()
f(1)
Expand All @@ -145,6 +150,7 @@ f(arg=1) # E: Unexpected keyword argument "arg" for "f"
f(arg="ERROR") # E: Unexpected keyword argument "arg" for "f"

[case testPEP570Calls]
# flags: --python-version 3.8 --no-strict-optional
from typing import Any, Dict
def f(p, /, p_or_kw, *, kw) -> None: ... # N: "f" defined here
d = None # type: Dict[Any, Any]
Expand All @@ -157,42 +163,49 @@ f(**d) # E: Missing positional argument "p_or_kw" in call to "f"
[builtins fixtures/dict.pyi]

[case testPEP570Signatures1]
# flags: --python-version 3.8
def f(p1: bytes, p2: float, /, p_or_kw: int, *, kw: str) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.float"
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"
reveal_type(kw) # N: Revealed type is "builtins.str"

[case testPEP570Signatures2]
# flags: --python-version 3.8
def f(p1: bytes, p2: float = 0.0, /, p_or_kw: int = 0, *, kw: str) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.float"
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"
reveal_type(kw) # N: Revealed type is "builtins.str"

[case testPEP570Signatures3]
# flags: --python-version 3.8
def f(p1: bytes, p2: float = 0.0, /, *, kw: int) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.float"
reveal_type(kw) # N: Revealed type is "builtins.int"

# flags: --python-version 3.8
[case testPEP570Signatures4]
def f(p1: bytes, p2: int = 0, /) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.int"

[case testPEP570Signatures5]
# flags: --python-version 3.8
def f(p1: bytes, p2: float, /, p_or_kw: int) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.float"
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"

[case testPEP570Signatures6]
# flags: --python-version 3.8
def f(p1: bytes, p2: float, /) -> None:
reveal_type(p1) # N: Revealed type is "builtins.bytes"
reveal_type(p2) # N: Revealed type is "builtins.float"

[case testPEP570Unannotated]
# flags: --python-version 3.8
def f(arg, /): ... # N: "f" defined here
g = lambda arg, /: arg
def h(arg=0, /): ... # N: "h" defined here
Expand Down Expand Up @@ -561,6 +574,7 @@ def foo() -> None:
[builtins fixtures/dict.pyi]

[case testOverloadWithPositionalOnlySelf]
# flags: --python-version 3.8
from typing import overload, Optional

class Foo:
Expand Down Expand Up @@ -678,6 +692,7 @@ main:16: note: def foo(cls, float, /) -> Any
main:16: note: def foo(cls, a: str) -> Any

[case testUnpackWithDuplicateNamePositionalOnly]
# flags: --python-version 3.8
from typing_extensions import Unpack, TypedDict

class Person(TypedDict):
Expand Down