Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/red_knot_python_semantic/resources/primer/bad.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Expression # cycle panic (signature_)
Tanjun # cycle panic (signature_)
aiohttp # missing expression ID
alerta # missing expression ID
Expand Down
1 change: 0 additions & 1 deletion crates/red_knot_python_semantic/resources/primer/good.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
AutoSplit
Expression
PyGithub
PyWinCtl
SinbadCogs
Expand Down
8 changes: 8 additions & 0 deletions crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -6467,6 +6473,7 @@ impl KnownFunction {
| Self::AssertNever
| Self::Cast
| Self::Overload
| Self::Override
| Self::RevealType
| Self::Final
| Self::IsProtocol
Expand Down Expand Up @@ -7844,6 +7851,7 @@ pub(crate) mod tests {
KnownFunction::Cast
| KnownFunction::Final
| KnownFunction::Overload
| KnownFunction::Override
| KnownFunction::RevealType
| KnownFunction::AssertType
| KnownFunction::AssertNever
Expand Down
16 changes: 16 additions & 0 deletions crates/red_knot_python_semantic/src/types/call/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
_ => {}
}
}
Expand Down
Loading