mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
[ty] Short circuit ReachabilityConstraints::analyze_single
for dynamic types (#19867)
This commit is contained in:
parent
dc84645c36
commit
2abd683376
2 changed files with 24 additions and 0 deletions
|
@ -505,3 +505,16 @@ class Abstract(Protocol):
|
||||||
class Concrete(Abstract):
|
class Concrete(Abstract):
|
||||||
def method(self) -> str: ... # error: [invalid-return-type]
|
def method(self) -> str: ... # error: [invalid-return-type]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Diagnostics for `invalid-return-type` on dynamic type
|
||||||
|
|
||||||
|
```toml
|
||||||
|
environment.python-version = "3.12"
|
||||||
|
```
|
||||||
|
|
||||||
|
```py
|
||||||
|
from typing import Never, Any
|
||||||
|
|
||||||
|
def f(func: Any) -> Never: # error: [invalid-return-type]
|
||||||
|
func()
|
||||||
|
```
|
||||||
|
|
|
@ -815,6 +815,17 @@ impl ReachabilityConstraints {
|
||||||
// very large in number, since we add them on all statement level function calls.
|
// very large in number, since we add them on all statement level function calls.
|
||||||
let ty = infer_expression_type(db, callable);
|
let ty = infer_expression_type(db, callable);
|
||||||
|
|
||||||
|
// Short-circuit for well known types that are known not to return `Never` when called.
|
||||||
|
// Without the short-circuit, we've seen that threads keep blocking each other
|
||||||
|
// because they all try to acquire Salsa's `CallableType` lock that ensures each type
|
||||||
|
// is only interned once. The lock is so heavily congested because there are only
|
||||||
|
// very few dynamic types, in which case Salsa's sharding the locks by value
|
||||||
|
// doesn't help much.
|
||||||
|
// See <https://github.com/astral-sh/ty/issues/968>.
|
||||||
|
if matches!(ty, Type::Dynamic(_)) {
|
||||||
|
return Truthiness::AlwaysFalse.negate_if(!predicate.is_positive);
|
||||||
|
}
|
||||||
|
|
||||||
let overloads_iterator =
|
let overloads_iterator =
|
||||||
if let Some(Type::Callable(callable)) = ty.into_callable(db) {
|
if let Some(Type::Callable(callable)) = ty.into_callable(db) {
|
||||||
callable.signatures(db).overloads.iter()
|
callable.signatures(db).overloads.iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue