Skip to content

Commit

Permalink
Fixed bug that resulted in a false negative when assigning to type `t…
Browse files Browse the repository at this point in the history
…uple[Never]`. This addresses #8237.
  • Loading branch information
erictraut committed Jun 26, 2024
1 parent b5d4d92 commit 427ca11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/pyright-internal/src/analyzer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,7 @@ export namespace ClassType {
newClassType.includeSubclasses = true;
}

newClassType.tupleTypeArguments = tupleTypeArguments?.map((t) =>
isNever(t.type) ? { type: UnknownType.create(), isUnbounded: t.isUnbounded, isOptional: t.isOptional } : t
);
newClassType.tupleTypeArguments = tupleTypeArguments ? [...tupleTypeArguments] : undefined;

if (isEmptyContainer !== undefined) {
newClassType.isEmptyContainer = isEmptyContainer;
Expand Down
13 changes: 12 additions & 1 deletion packages/pyright-internal/src/tests/samples/tuple1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This sample file tests various aspects of type analysis for tuples.

import os
from typing import Any, Callable
from typing import Any, Callable, Never

from typing_extensions import ( # pyright: ignore[reportMissingModuleSource]
TypeVarTuple,
Unpack,
Expand Down Expand Up @@ -270,3 +271,13 @@ def func19(a: tuple[int, ...], b: tuple[int, *tuple[int, ...]]):

# This should generate an error.
b5: tuple[int, int, *tuple[int, ...]] = b


def func20(v: tuple[Never]):
# This should generate an error.
x1: tuple[Never] = (1,)

# This should generate an error.
x2: tuple[Never] = ()

x3: tuple[Never] = v
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/typeEvaluator8.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ test('Optional2', () => {
test('Tuple1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['tuple1.py']);

TestUtils.validateResults(analysisResults, 24);
TestUtils.validateResults(analysisResults, 26);
});

test('Tuple2', () => {
Expand Down

0 comments on commit 427ca11

Please sign in to comment.