[ty] Sync vendored typeshed stubs (#20658)

---------

Co-authored-by: typeshedbot <>
Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
github-actions[bot] 2025-10-01 10:11:48 +02:00 committed by GitHub
parent a422716267
commit d9473a2fcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 1024 additions and 979 deletions

View file

@ -4403,8 +4403,8 @@ impl KnownClass {
KnownClassDisplay { db, class: self }
}
/// Lookup a [`KnownClass`] in typeshed and return a [`Type`]
/// representing all possible instances of the class.
/// Lookup a [`KnownClass`] in typeshed and return a [`Type`] representing all possible instances of
/// the class. If this class is generic, this will use the default specialization.
///
/// If the class cannot be found in typeshed, a debug-level log message will be emitted stating this.
pub(crate) fn to_instance(self, db: &dyn Db) -> Type<'_> {
@ -4414,6 +4414,14 @@ impl KnownClass {
.unwrap_or_else(Type::unknown)
}
/// Similar to [`KnownClass::to_instance`], but returns the Unknown-specialization where each type
/// parameter is specialized to `Unknown`.
pub(crate) fn to_instance_unknown(self, db: &dyn Db) -> Type<'_> {
self.try_to_class_literal(db)
.map(|literal| Type::instance(db, literal.unknown_specialization(db)))
.unwrap_or_else(Type::unknown)
}
/// Lookup a generic [`KnownClass`] in typeshed and return a [`Type`]
/// representing a specialization of that class.
///

View file

@ -1923,8 +1923,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
//
// If type arguments are supplied to `(Async)Iterable`, `(Async)Iterator`,
// `(Async)Generator` or `(Async)GeneratorType` in the return annotation,
// we should iterate over the `yield` expressions and `return` statements in the function
// to check that they are consistent with the type arguments provided.
// we should iterate over the `yield` expressions and `return` statements
// in the function to check that they are consistent with the type arguments
// provided. Once we do this, the `.to_instance_unknown` call below should
// be replaced with `.to_specialized_instance`.
let inferred_return = if function.is_async {
KnownClass::AsyncGeneratorType
} else {
@ -1932,7 +1934,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
};
if !inferred_return
.to_instance(self.db())
.to_instance_unknown(self.db())
.is_assignable_to(self.db(), expected_ty)
{
report_invalid_generator_function_return_type(