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
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,31 @@ class BarNone(Protocol):
static_assert(is_disjoint_from(type[Foo], BarNone))
```

### `NamedTuple`

```py
from __future__ import annotations

from typing import NamedTuple, final
from ty_extensions import is_disjoint_from, static_assert

@final
class Path(NamedTuple):
prev: Path | None
key: str

@final
class Path2(NamedTuple):
prev: Path2 | None
key: str

static_assert(not is_disjoint_from(Path, Path))
static_assert(not is_disjoint_from(Path, tuple[Path | None, str]))
static_assert(is_disjoint_from(Path, tuple[Path | None]))
static_assert(is_disjoint_from(Path, tuple[Path | None, str, int]))
static_assert(is_disjoint_from(Path, Path2))
```

## Callables

No two callable types are disjoint because there exists a non-empty callable type
Expand Down
7 changes: 4 additions & 3 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,9 +2553,10 @@ impl<'db> Type<'db> {
other.is_disjoint_from_impl(db, KnownClass::ModuleType.to_instance(db), visitor)
}

(Type::NominalInstance(left), Type::NominalInstance(right)) => {
left.is_disjoint_from_impl(db, right, visitor)
}
(Type::NominalInstance(left), Type::NominalInstance(right)) => visitor
.visit((self, other), || {
left.is_disjoint_from_impl(db, right, visitor)
}),

(Type::PropertyInstance(_), other) | (other, Type::PropertyInstance(_)) => {
KnownClass::Property
Expand Down
Loading