[ty] Infer ParamSpec from class constructors for callable protocols#22853
[ty] Infer ParamSpec from class constructors for callable protocols#22853charliermarsh merged 1 commit intomainfrom
ParamSpec from class constructors for callable protocols#22853Conversation
Typing conformance resultsNo changes detected ✅ |
|
12cdb42 to
4f0fa4d
Compare
|
Unless I'm mistaken, I think the second comment (astral-sh/ty#2587 (comment)) is a separate issue. |
|
I believe the |
AlexWaygood
left a comment
There was a problem hiding this comment.
I'm a bit hesitant to make too many changes to how generic protocols work while #21902 is still in progress (it should land this week, hopefully). Having said that, the tests you've added don't appear to be fixed by Doug's branch there, and it's true that __call__ members on protocols need to be quite heavily special-cased (sadly)
| # error: [invalid-argument-type] | ||
| create(MyType, "wrong type") |
There was a problem hiding this comment.
| # error: [invalid-argument-type] | |
| create(MyType, "wrong type") | |
| # error: [too-many-positional-arguments] | |
| create(MyType, 1, 2) | |
| # error: [missing-argument] | |
| # error: [unknown-argument] | |
| create(MyType, y=2) | |
| # error: [unknown-argument] | |
| create(MyType, x=1, y=2) | |
| # error: [invalid-argument-type] | |
| create(MyType, "wrong type") |
| class NoArgs(ParentClass): | ||
| pass | ||
|
|
||
| create(NoArgs) # OK - P is inferred as [] |
There was a problem hiding this comment.
| create(NoArgs) # OK - P is inferred as [] | |
| create(NoArgs) # OK - P is inferred as [] | |
| create(NoArgs, 1) # error: [too-many-positional-arguments] |
|
(I'd like @dcreager's review on this one!) |
dcreager
left a comment
There was a problem hiding this comment.
I'm a bit hesitant to make too many changes to how generic protocols work while #21902 is still in progress (it should land this week, hopefully). Having said that, the tests you've added don't appear to be fixed by Doug's branch there, and it's true that
__call__members on protocols need to be quite heavily special-cased (sadly)
👍 Code looks good! This does not look to conflict much with #21902.
| } | ||
|
|
||
| /// Infer type mappings by comparing formal callable signatures against actual callables. | ||
| fn infer_from_callable_signature( |
* main: (48 commits) add info for non_octal permissions (#22972) Fix empty body rule rendering (#23039) [ty] Infer `ParamSpec` from class constructors for callable protocols (#22853) Update NPM Development dependencies (#23030) Update CodSpeedHQ/action action to v4.8.2 (#23029) [ty] remove special handling for `Any()` in match class patterns (#23011) Update Rust crate get-size2 to v0.7.4 (#23022) Update Rust crate insta to v1.46.1 (#23023) Update taiki-e/install-action action to v2.67.11 (#23033) Update Rust crate colored to v3.1.1 (#23031) Update cargo-bins/cargo-binstall action to v1.17.3 (#23028) Update Rust crate uuid to v1.20.0 (#23032) [ty] Avoid using `.node()` for detecting `Self` (#23000) Update Rust crate proc-macro2 to v1.0.106 (#23024) Update actions/setup-python action to v6.2.0 (#23027) [ty] fix query cycles in decorated function with parameter defaults (#23014) Update Rust crate quote to v1.0.44 (#23025) Update Rust crate thiserror to v2.0.18 (#23026) Update Rust crate filetime to v0.2.27 (#23021) Update Rust crate clearscreen to v4.0.3 (#23020) ...
Summary
Closes astral-sh/ty#2587.