[ty] Treat functions, methods, and dynamic types as function-like Callables#20842
[ty] Treat functions, methods, and dynamic types as function-like Callables#20842
Callables#20842Conversation
Callables
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
possibly-missing-attribute |
0 | 12 | 0 |
unresolved-attribute |
0 | 2 | 0 |
| Total | 0 | 14 | 0 |
b1ea6cb to
964d912
Compare
964d912 to
b221247
Compare
There was a problem hiding this comment.
do we really not already have tests like these somewhere...?
crates/ty_python_semantic/resources/mdtest/type_properties/is_equivalent_to.md
Outdated
Show resolved
Hide resolved
| Note that `variadic_without_annotation` and `variadic_with_annotation` are *not* considered | ||
| gradually equivalent to `Callable[..., Any]`, because the latter is not a function-like callable | ||
| type: | ||
|
|
||
| ```py | ||
| static_assert(not is_equivalent_to(CallableTypeOf[variadic_without_annotation], Callable[..., Any])) | ||
| static_assert(not is_equivalent_to(CallableTypeOf[variadic_with_annotation], Callable[..., Any])) | ||
| ``` | ||
|
|
||
| A function with either `*args` or `**kwargs` (and not both) is is not equivalent to a callable with | ||
| `...` as the parameter type. |
| .map(|signature| signature.bind_self(db, Some(self_instance))), | ||
| ), | ||
| false, | ||
| true, |
There was a problem hiding this comment.
strictly speaking, if we're doing it this way rather than with intersections, I suppose we should also have a method_like: bool flag for BoundMethodTypes -- methods not only have all the attributes that functions have, but they also have attributes such as __closure__ that functions do not have
(Not blocking for this PR, though, of course)
There was a problem hiding this comment.
I very much like the Callable[…] & FunctionType / Callable[…] & BoundMethodType approach, but I'd like to move on with this for now, to get to what I'm actually trying to achieve 😄
There was a problem hiding this comment.
yeah ikik, that's why I said this is non-blocking 😄
…tity * origin/main: (24 commits) Update Python compatibility from 3.13 to 3.14 in README.md (#20852) [syntax-errors]: break outside loop F701 (#20556) [ty] Treat `Callable`s as bound-method descriptors in special cases (#20802) [ty] Do not bind self to non-positional parameters (#20850) Fix syntax error false positives on parenthesized context managers (#20846) [ty] Remove 'pre-release software' warning (#20817) Render unsupported syntax errors in formatter tests (#20777) [ty] Treat functions, methods, and dynamic types as function-like `Callable`s (#20842) [ty] Move logic for `super()` inference to a new `types::bound_super` submodule (#20840) [ty] Fix false-positive diagnostics on `super()` calls (#20814) [ty] Move `class_member` to `member` module (#20837) [`ruff`] Use DiagnosticTag for more flake8 and numpy rules (#20758) [ty] Prefer declared base class attribute over inferred attribute on subclass (#20764) [ty] Log files that are slow to type check (#20836) Update cargo-bins/cargo-binstall action to v1.15.7 (#20827) Update CodSpeedHQ/action action to v4.1.1 (#20828) Update Rust crate pyproject-toml to v0.13.7 (#20835) Update Rust crate anstream to v0.6.21 (#20829) Update Rust crate libc to v0.2.177 (#20832) Update Rust crate memchr to v2.7.6 (#20834) ...
* main: (25 commits) [ty] Diagnostic for generic classes that reference typevars in enclosing scope (#20822) Update Python compatibility from 3.13 to 3.14 in README.md (#20852) [syntax-errors]: break outside loop F701 (#20556) [ty] Treat `Callable`s as bound-method descriptors in special cases (#20802) [ty] Do not bind self to non-positional parameters (#20850) Fix syntax error false positives on parenthesized context managers (#20846) [ty] Remove 'pre-release software' warning (#20817) Render unsupported syntax errors in formatter tests (#20777) [ty] Treat functions, methods, and dynamic types as function-like `Callable`s (#20842) [ty] Move logic for `super()` inference to a new `types::bound_super` submodule (#20840) [ty] Fix false-positive diagnostics on `super()` calls (#20814) [ty] Move `class_member` to `member` module (#20837) [`ruff`] Use DiagnosticTag for more flake8 and numpy rules (#20758) [ty] Prefer declared base class attribute over inferred attribute on subclass (#20764) [ty] Log files that are slow to type check (#20836) Update cargo-bins/cargo-binstall action to v1.15.7 (#20827) Update CodSpeedHQ/action action to v4.1.1 (#20828) Update Rust crate pyproject-toml to v0.13.7 (#20835) Update Rust crate anstream to v0.6.21 (#20829) Update Rust crate libc to v0.2.177 (#20832) ...
…rable * origin/main: (26 commits) [ty] Add separate type for typevar "identity" (#20813) [ty] Diagnostic for generic classes that reference typevars in enclosing scope (#20822) Update Python compatibility from 3.13 to 3.14 in README.md (#20852) [syntax-errors]: break outside loop F701 (#20556) [ty] Treat `Callable`s as bound-method descriptors in special cases (#20802) [ty] Do not bind self to non-positional parameters (#20850) Fix syntax error false positives on parenthesized context managers (#20846) [ty] Remove 'pre-release software' warning (#20817) Render unsupported syntax errors in formatter tests (#20777) [ty] Treat functions, methods, and dynamic types as function-like `Callable`s (#20842) [ty] Move logic for `super()` inference to a new `types::bound_super` submodule (#20840) [ty] Fix false-positive diagnostics on `super()` calls (#20814) [ty] Move `class_member` to `member` module (#20837) [`ruff`] Use DiagnosticTag for more flake8 and numpy rules (#20758) [ty] Prefer declared base class attribute over inferred attribute on subclass (#20764) [ty] Log files that are slow to type check (#20836) Update cargo-bins/cargo-binstall action to v1.15.7 (#20827) Update CodSpeedHQ/action action to v4.1.1 (#20828) Update Rust crate pyproject-toml to v0.13.7 (#20835) Update Rust crate anstream to v0.6.21 (#20829) ...
Summary
Treat functions, methods, and dynamic types as function-like
Callablescloses astral-sh/ty#1342
closes astral-sh/ty#1344
Ecosystem analysis
All removed diagnostics look like cases of astral-sh/ty#1344
Test Plan
Added regression test