Skip to content

Commit 8996f91

Browse files
committed
Removed remaining code that was left over from PEP 637, which was rejected.
1 parent f7285d9 commit 8996f91

4 files changed

Lines changed: 10 additions & 196 deletions

File tree

packages/pyright-internal/src/analyzer/typeEvaluator.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8119,13 +8119,9 @@ export function createTypeEvaluator(
81198119
}
81208120
}
81218121

8122-
// Follow PEP 637 rules for positional and keyword arguments.
8123-
const positionalArgs = node.d.items.filter((item) => item.d.argCategory === ArgCategory.Simple && !item.d.name);
8122+
const positionalArgs = node.d.items.filter((item) => item.d.argCategory === ArgCategory.Simple);
81248123
const unpackedListArgs = node.d.items.filter((item) => item.d.argCategory === ArgCategory.UnpackedList);
81258124

8126-
const keywordArgs = node.d.items.filter((item) => item.d.argCategory === ArgCategory.Simple && !!item.d.name);
8127-
const unpackedDictArgs = node.d.items.filter((item) => item.d.argCategory === ArgCategory.UnpackedDictionary);
8128-
81298125
let positionalIndexType: Type;
81308126
let isPositionalIndexTypeIncomplete = false;
81318127

@@ -8136,9 +8132,6 @@ export function createTypeEvaluator(
81368132
if (typeResult.isIncomplete) {
81378133
isPositionalIndexTypeIncomplete = true;
81388134
}
8139-
} else if (positionalArgs.length === 0 && unpackedListArgs.length === 0) {
8140-
// Handle the case where there are no positionals provided but there are keywords.
8141-
positionalIndexType = makeTupleObject(evaluatorInterface, []);
81428135
} else {
81438136
// Package up all of the positionals into a tuple.
81448137
const tupleTypeArgs: TupleTypeArg[] = [];
@@ -8192,23 +8185,6 @@ export function createTypeEvaluator(
81928185
});
81938186
}
81948187

8195-
keywordArgs.forEach((arg) => {
8196-
argList.push({
8197-
argCategory: ArgCategory.Simple,
8198-
valueExpression: arg.d.valueExpr,
8199-
node: arg,
8200-
name: arg.d.name,
8201-
});
8202-
});
8203-
8204-
unpackedDictArgs.forEach((arg) => {
8205-
argList.push({
8206-
argCategory: ArgCategory.UnpackedDictionary,
8207-
valueExpression: arg.d.valueExpr,
8208-
node: arg,
8209-
});
8210-
});
8211-
82128188
const callResult = validateCallArgs(
82138189
node,
82148190
argList,
Lines changed: 7 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,10 @@
1-
# This sample tests subscript forms specified in PEP 637 -
2-
# keyword and unpacked args.
1+
# This sample tests the handling of a subscript in a loop that includes
2+
# a del statement.
33

4-
from typing import Any, Union, overload
4+
# pyright: strict
55

66

7-
class ClassA:
8-
@overload
9-
def __getitem__(self, index: int) -> int:
10-
...
11-
12-
@overload
13-
def __getitem__(self, index: tuple[int, ...]) -> float:
14-
...
15-
16-
@overload
17-
def __getitem__(self, index: Any, *, v1: int) -> str:
18-
...
19-
20-
def __getitem__(self, index: Any, *, v1: int = 3) -> Union[str, float]:
21-
...
22-
23-
@overload
24-
def __setitem__(self, index: int, value: int) -> None:
25-
...
26-
27-
@overload
28-
def __setitem__(self, index: tuple[int, ...], value: float) -> None:
29-
...
30-
31-
@overload
32-
def __setitem__(self, index: Any, value: str, *, v1: int) -> None:
33-
...
34-
35-
def __setitem__(self, index: Any, value: Union[str, float], *, v1: int = 3) -> None:
36-
...
37-
38-
39-
val_list = [1, 2, 3]
40-
val_dict = {"a": 2, "b": 2}
41-
42-
a_obj = ClassA()
43-
44-
x1 = a_obj[1]
45-
reveal_type(x1, expected_text="int")
46-
47-
a_obj[1] = 3
48-
49-
# This should generate an error because float isn't assignable.
50-
a_obj[1] = 3.5
51-
52-
x2 = a_obj[1,]
53-
reveal_type(x2, expected_text="float")
54-
55-
a_obj[1,] = 3.4
56-
57-
# This should generate an error because complex isn't assignable.
58-
a_obj[1,] = 3.5j
59-
60-
x3 = a_obj[1,2]
61-
reveal_type(x3, expected_text="float")
62-
63-
a_obj[1,2] = 4.5
64-
65-
# This should generate an error because complex isn't assignable.
66-
a_obj[1,2] = 3.5j
67-
68-
x4 = a_obj[(1,)]
69-
reveal_type(x4, expected_text="float")
70-
71-
a_obj[(1,)] = 3
72-
73-
# This should generate an error because complex isn't assignable.
74-
a_obj[(1,)] = 3.5j
75-
76-
x6 = a_obj[1, v1=3]
77-
reveal_type(x6, expected_text="str")
78-
79-
a_obj[1, v1=3] = "hi"
80-
81-
# This should generate an error because complex isn't assignable.
82-
a_obj[1,v1=3] = 3.5j
83-
84-
85-
x8 = a_obj[1, *val_list]
86-
reveal_type(x8, expected_text="float")
87-
88-
a_obj[1, *val_list] = 4.3
89-
90-
# This should generate an error because complex isn't assignable.
91-
a_obj[1, *val_list] = 4.3j
92-
93-
94-
95-
class ClassB:
96-
def __getitem__(self, value: tuple[()], *, v1: int) -> str:
97-
...
98-
99-
b_obj = ClassB()
100-
101-
# This should generate an error because positional args are not allowed.
102-
y1 = b_obj[1]
103-
104-
y2 = b_obj[v1=3]
105-
reveal_type(y2, expected_text="str")
106-
107-
# This should generate an error because v2 is not a named arg.
108-
y3 = b_obj[v2=3]
109-
110-
111-
class ClassC:
112-
def __getitem__(self, index: Any, **kwargs: int) -> complex:
113-
...
114-
115-
def __setitem__(self, index: Any, value: float, **kwargs: int) -> None:
116-
...
117-
118-
c_obj = ClassC()
119-
120-
z1 = c_obj[1, *val_list]
121-
reveal_type(z1, expected_text="complex")
122-
123-
# This should generate an error because dictionary unpack isn't allowed in subscript.
124-
z2 = c_obj[1, *val_list, **val_dict]
125-
126-
c_obj[1, *val_list] = 4.3
127-
128-
# This should generate an error because dictionary unpack isn't allowed in subscript.
129-
c_obj[1, *val_list, **val_dict] = 4.3
130-
131-
# This should generate an error because complex isn't assignable.
132-
c_obj[1, *val_list] = 4.3j
133-
134-
135-
z2 = c_obj[1, v1=3, v2=4]
136-
reveal_type(z2, expected_text="complex")
137-
138-
c_obj[1, v1=3, v2=4] = 4.3
139-
140-
# This should generate an error because complex isn't assignable.
141-
c_obj[1, v1=3, v2=4] = 4.3j
7+
def func1(lst: list[tuple[int, int]]):
8+
for _ in range(1):
9+
lst[-1] = lst[-1][1], lst[-1][0]
10+
del lst[-1]

packages/pyright-internal/src/tests/samples/subscript4.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/pyright-internal/src/tests/typeEvaluator6.test.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
*/
1010

1111
import { ConfigOptions } from '../common/configOptions';
12-
import {
13-
pythonVersion3_10,
14-
pythonVersion3_11,
15-
pythonVersion3_12,
16-
pythonVersion3_8,
17-
pythonVersion3_9,
18-
} from '../common/pythonVersion';
12+
import { pythonVersion3_10, pythonVersion3_11, pythonVersion3_12, pythonVersion3_8 } from '../common/pythonVersion';
1913
import { Uri } from '../common/uri/uri';
2014
import * as TestUtils from './testUtils';
2115

@@ -966,22 +960,7 @@ test('Subscript2', () => {
966960
});
967961

968962
test('Subscript3', () => {
969-
const configOptions = new ConfigOptions(Uri.empty());
970-
971-
// Analyze with Python 3.9 settings.
972-
configOptions.defaultPythonVersion = pythonVersion3_9;
973-
const analysisResults39 = TestUtils.typeAnalyzeSampleFiles(['subscript3.py'], configOptions);
974-
TestUtils.validateResults(analysisResults39, 37);
975-
976-
// Analyze with Python 3.10 settings.
977-
// These are disabled because PEP 637 was rejected.
978-
// configOptions.defaultPythonVersion = pythonVersion3_10;
979-
// const analysisResults310 = TestUtils.typeAnalyzeSampleFiles(['subscript3.py'], configOptions);
980-
// TestUtils.validateResults(analysisResults310, 11);
981-
});
982-
983-
test('Subscript4', () => {
984-
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['subscript4.py']);
963+
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['subscript3.py']);
985964
TestUtils.validateResults(analysisResults, 0);
986965
});
987966

0 commit comments

Comments
 (0)