diff --git a/crates/red_knot_python_semantic/resources/primer/bad.txt b/crates/red_knot_python_semantic/resources/primer/bad.txt index d263c922c9186..24a74e3ac9477 100644 --- a/crates/red_knot_python_semantic/resources/primer/bad.txt +++ b/crates/red_knot_python_semantic/resources/primer/bad.txt @@ -1,3 +1,4 @@ +Expression # cycle panic (signature_) Tanjun # cycle panic (signature_) aiohttp # missing expression ID alerta # missing expression ID diff --git a/crates/red_knot_python_semantic/resources/primer/good.txt b/crates/red_knot_python_semantic/resources/primer/good.txt index 86cec204df8f5..f76755770702a 100644 --- a/crates/red_knot_python_semantic/resources/primer/good.txt +++ b/crates/red_knot_python_semantic/resources/primer/good.txt @@ -1,5 +1,4 @@ AutoSplit -Expression PyGithub PyWinCtl SinbadCogs diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index 44ce5f1561f08..dfc55c73ffe3b 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -6027,6 +6027,10 @@ bitflags! { const OVERLOAD = 1 << 2; /// `@abc.abstractmethod` const ABSTRACT_METHOD = 1 << 3; + /// `@typing.final` + const FINAL = 1 << 4; + /// `@typing.override` + const OVERRIDE = 1 << 6; } } @@ -6400,6 +6404,8 @@ pub enum KnownFunction { Cast, /// `typing(_extensions).overload` Overload, + /// `typing(_extensions).override` + Override, /// `typing(_extensions).is_protocol` IsProtocol, /// `typing(_extensions).get_protocol_members` @@ -6467,6 +6473,7 @@ impl KnownFunction { | Self::AssertNever | Self::Cast | Self::Overload + | Self::Override | Self::RevealType | Self::Final | Self::IsProtocol @@ -7844,6 +7851,7 @@ pub(crate) mod tests { KnownFunction::Cast | KnownFunction::Final | KnownFunction::Overload + | KnownFunction::Override | KnownFunction::RevealType | KnownFunction::AssertType | KnownFunction::AssertNever diff --git a/crates/red_knot_python_semantic/src/types/call/bind.rs b/crates/red_knot_python_semantic/src/types/call/bind.rs index 3e519a6a835e6..397c2aaa118e2 100644 --- a/crates/red_knot_python_semantic/src/types/call/bind.rs +++ b/crates/red_knot_python_semantic/src/types/call/bind.rs @@ -584,6 +584,14 @@ impl<'db> Bindings<'db> { } } + Some(KnownFunction::Override) => { + // TODO: This can be removed once we understand legacy generics because the + // typeshed definition for `typing.overload` is an identity function. + if let [Some(ty)] = overload.parameter_types() { + overload.set_return_type(*ty); + } + } + Some(KnownFunction::AbstractMethod) => { // TODO: This can be removed once we understand legacy generics because the // typeshed definition for `abc.abstractmethod` is an identity function. @@ -592,6 +600,14 @@ impl<'db> Bindings<'db> { } } + Some(KnownFunction::Final) => { + // TODO: This can be removed once we understand legacy generics because the + // typeshed definition for `abc.abstractmethod` is an identity function. + if let [Some(ty)] = overload.parameter_types() { + overload.set_return_type(*ty); + } + } + Some(KnownFunction::GetattrStatic) => { let [Some(instance_ty), Some(attr_name), default] = overload.parameter_types() diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 8bda7530d7f2b..bfdddc49827fb 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -1500,6 +1500,14 @@ impl<'db> TypeInferenceBuilder<'db> { function_decorators |= FunctionDecorators::ABSTRACT_METHOD; continue; } + Some(KnownFunction::Final) => { + function_decorators |= FunctionDecorators::FINAL; + continue; + } + Some(KnownFunction::Override) => { + function_decorators |= FunctionDecorators::OVERRIDE; + continue; + } _ => {} } }