File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
crates/ty_python_semantic
resources/mdtest/function Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -505,3 +505,16 @@ class Abstract(Protocol):
505505class Concrete (Abstract ):
506506 def method (self ) -> str : ... # error: [invalid-return-type]
507507```
508+
509+ ## Diagnostics for ` invalid-return-type ` on dynamic type
510+
511+ ``` toml
512+ environment.python-version = " 3.12"
513+ ```
514+
515+ ``` py
516+ from typing import Never, Any
517+
518+ def f (func : Any) -> Never: # error: [invalid-return-type]
519+ func()
520+ ```
Original file line number Diff line number Diff line change @@ -815,6 +815,17 @@ impl ReachabilityConstraints {
815815 // very large in number, since we add them on all statement level function calls.
816816 let ty = infer_expression_type ( db, callable) ;
817817
818+ // Short-circuit for well known types that are known not to return `Never` when called.
819+ // Without the short-circuit, we've seen that threads keep blocking each other
820+ // because they all try to acquire Salsa's `CallableType` lock that ensures each type
821+ // is only interned once. The lock is so heavily congested because there are only
822+ // very few dynamic types, in which case Salsa's sharding the locks by value
823+ // doesn't help much.
824+ // See <https://github.com/astral-sh/ty/issues/968>.
825+ if matches ! ( ty, Type :: Dynamic ( _) ) {
826+ return Truthiness :: AlwaysFalse . negate_if ( !predicate. is_positive ) ;
827+ }
828+
818829 let overloads_iterator =
819830 if let Some ( Type :: Callable ( callable) ) = ty. into_callable ( db) {
820831 callable. signatures ( db) . overloads . iter ( )
You can’t perform that action at this time.
0 commit comments