[ty] Add mdtest suite for typing.Concatenate#23554
Conversation
| def _(c: Callable[[Concatenate[int, str, ...], int], int]): | ||
| # TODO: Should reveal the correct signature | ||
| reveal_type(c) # revealed: (...) -> int | ||
| ``` |
There was a problem hiding this comment.
This is removed because I don't think it's true that Concatenate is allowed within the parameter list of a Callable annotation.
| from typing import Callable, Concatenate | ||
|
|
||
| def _(c: Callable[Concatenate[int, str, ...], bool]): | ||
| # TODO: Should reveal `(int, str, /, ...) -> bool` |
There was a problem hiding this comment.
or (int, str, /, *args: Unknown, **kwargs: Unknown) -> bool since, per the spec, *args: Unknown, **kwargs: Unknown is equivalent to ..., even in a signature that has other parameters besides *args, **kwargs. And I think I'd prefer spelling this type as (int, str, /, *args: Unknown, **kwargs: Unknown) -> bool -- it has the advantage that it's valid Python syntax for a function declaration, which is nice!
There was a problem hiding this comment.
Yes, that's correct but we've been using ... to display the gradual form everywhere:
from typing import Callable
def _(x: Callable[..., None]):
reveal_type(x) # revealed: (...) -> NoneI think mypy does spell it out although without the parameter names (def (*Any, **Any)) and we do store the gradual form as *args: Any, **kwargs: Any internally.
There was a problem hiding this comment.
Yes, that's correct but we've been using
...to display the gradual form everywhere:
Right, and that feels intuitive to me — but combining the... with other parameters in the list feels like a sorta confusing hybrid of valid syntax and invalid syntax 😆
Anyway, no need to spend time on this now since it's just a TODO comment for now anyway, and display implementations are easy to change later as well!
| from typing import Concatenate | ||
|
|
||
| # error: [invalid-type-form] "`typing.Concatenate` requires at least two arguments when used in a type expression" | ||
| def _(x: Concatenate): ... | ||
|
|
||
| # TODO: Should be an error - Concatenate is not a valid standalone type | ||
| def invalid1(x: Concatenate[int, ...]) -> None: ... | ||
|
|
||
| # TODO: Should be an error - Concatenate is not a valid standalone type | ||
| def invalid2() -> Concatenate[int, ...]: ... |
There was a problem hiding this comment.
For the missing validation here -- we should be able to use the same (or if not, similar) hooks to the ones I'm adding in #23625, I think
There was a problem hiding this comment.
Yeah, I think so, thanks!
crates/ty_python_semantic/resources/mdtest/generics/pep695/concatenate.md
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/generics/pep695/concatenate.md
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/generics/pep695/concatenate.md
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/generics/pep695/concatenate.md
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md
Outdated
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md
Outdated
Show resolved
Hide resolved
8b9d2d5 to
acb4e24
Compare
acb4e24 to
ec9a00d
Compare
* main: [ty] Apply narrowing to walrus values (#23687) [`perflint`] Extend `PERF102` to comprehensions and generators (#23473) [ty] Fix GitHub-annotations mdtest output format (#23694) [ty] Reduce the number of potentially-flaky projects (#23698) [`pydocstyle`] Fix numpy section ordering (`D420`) (#23685) [ty] Move method-related types to a submodule (#23691) [ty] Avoid the mandatory "ecosystem-analyzer workflow run cancelled" notification every time you make a PR (#23695) [ty] Move `Type::subtyping_is_always_reflexive` to `types::relation` (#23692) Update conformance suite commit hash (#23693) [ty] Add mdtest suite for `typing.Concatenate` (#23554) [ty] filter out pre-loop bindings from loop headers (#23536)
Summary
This PR adds a comprehensive test suite for
typing.Concatenatein preparation for astral-sh/ty#1535 and to help the review process in #23119.Test Plan
Run mdtest.