mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
[ty] Set None as the definition of Self type variables (#22648)
This commit is contained in:
@@ -4623,9 +4623,7 @@ impl<'db> BindingError<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
if !typevar.is_self(context.db())
|
||||
&& let Some(typevar_definition) = typevar.definition(context.db())
|
||||
{
|
||||
if let Some(typevar_definition) = typevar.definition(context.db()) {
|
||||
let module = parsed_module(context.db(), typevar_definition.file(context.db()))
|
||||
.load(context.db());
|
||||
let typevar_range = typevar_definition.full_range(context.db(), &module);
|
||||
|
||||
@@ -96,7 +96,14 @@ pub(crate) fn typing_self<'db>(
|
||||
let identity = TypeVarIdentity::new(
|
||||
db,
|
||||
ast::name::Name::new_static("Self"),
|
||||
class.definition(db),
|
||||
// `Self` has a different upper bound dependent on the containing class,
|
||||
// so pointing to the definition of the symbol `typing.Self` itself is
|
||||
// not useful here. We could point to the class definition, but the full
|
||||
// range of the class definition is much larger than the full range of a
|
||||
// TypeVar would usually be, which leads to bugs like
|
||||
// https://github.com/astral-sh/ty/issues/2514. So we just pass `None`
|
||||
// for the definition field here.
|
||||
None,
|
||||
TypeVarKind::TypingSelf,
|
||||
);
|
||||
let bounds = TypeVarBoundOrConstraints::UpperBound(Type::instance(
|
||||
|
||||
Reference in New Issue
Block a user