[ty] Do not emit errors if enums or NamedTuples constructed using functional syntax are used in type expressions (#17873)

## Summary

This fixes some false positives that showed up in the primer diff for
https://github.com/astral-sh/ruff/pull/17832

## Test Plan

new mdtests added that fail with false-positive diagnostics on `main`
This commit is contained in:
Alex Waygood 2025-05-06 00:37:24 +01:00 committed by GitHub
parent fd76d70a31
commit 89424cce5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -4833,6 +4833,17 @@ impl<'db> Type<'db> {
Some(KnownClass::UnionType) => Ok(todo_type!(
"Support for `types.UnionType` instances in type expressions"
)),
Some(KnownClass::NamedTuple) => Ok(todo_type!(
"Support for functional `typing.NamedTuple` syntax"
)),
_ if instance
.class()
.iter_mro(db)
.filter_map(ClassBase::into_class)
.any(|class| class.is_known(db, KnownClass::Enum)) =>
{
Ok(todo_type!("Support for functional `enum` syntax"))
}
_ => Err(InvalidTypeExpressionError {
invalid_expressions: smallvec::smallvec![InvalidTypeExpression::InvalidType(
*self