@@ -1079,32 +1079,34 @@ def get(self) -> _T:
1079
1079
public async Task GenericForwardRef ( ) {
1080
1080
const string code = @"
1081
1081
from typing import List, Dict
1082
+
1083
+ x = List['A']
1084
+ y = Dict['A', 'B']
1085
+
1082
1086
class A:
1083
1087
def test(self) -> int:
1084
1088
pass
1085
1089
class B:
1086
1090
def test(self) -> int:
1087
1091
pass
1088
- l = List['A']
1089
- d = Dict['A', 'B']
1092
+ z = List['A']
1093
+ w = Dict['A', 'B']
1090
1094
" ;
1091
1095
var analysis = await GetAnalysisAsync ( code , PythonVersions . LatestAvailable3X ) ;
1092
- analysis . Should ( ) . HaveVariable ( "l " )
1096
+ analysis . Should ( ) . HaveVariable ( "x " )
1093
1097
. Which . Should ( ) . HaveType ( "List[A]" ) ;
1094
- analysis . Should ( ) . HaveVariable ( "d" )
1098
+ analysis . Should ( ) . HaveVariable ( "y" )
1099
+ . Which . Should ( ) . HaveType ( "Dict[A, B]" ) ;
1100
+ analysis . Should ( ) . HaveVariable ( "z" )
1101
+ . Which . Should ( ) . HaveType ( "List[A]" ) ;
1102
+ analysis . Should ( ) . HaveVariable ( "w" )
1095
1103
. Which . Should ( ) . HaveType ( "Dict[A, B]" ) ;
1096
1104
}
1097
1105
1098
1106
[ TestMethod , Priority ( 0 ) ]
1099
1107
public async Task GenericBuiltinTypeForwardRef ( ) {
1100
1108
const string code = @"
1101
1109
from typing import List, Dict
1102
- class A:
1103
- def test(self) -> int:
1104
- pass
1105
- class B:
1106
- def test(self) -> int:
1107
- pass
1108
1110
l = List['int']
1109
1111
d = Dict['float', 'str']
1110
1112
" ;
@@ -1119,15 +1121,16 @@ def test(self) -> int:
1119
1121
public async Task GenericListForwardRef ( ) {
1120
1122
const string code = @"
1121
1123
from typing import List, Dict
1122
- class A: ...
1123
- class B: ...
1124
1124
1125
1125
def test() -> 'List[A]':
1126
1126
pass
1127
1127
1128
1128
def test1() -> 'Dict[A, B]':
1129
1129
pass
1130
1130
1131
+ class A: ...
1132
+ class B: ...
1133
+
1131
1134
x = test()
1132
1135
y = test1()
1133
1136
" ;
@@ -1147,23 +1150,55 @@ public async Task GenericClassForwardRef() {
1147
1150
T = TypeVar('T')
1148
1151
K = TypeVar('K')
1149
1152
1150
- class A(Generic[T]):
1151
- def test(self) -> T:
1152
- pass
1153
-
1154
1153
class B(Generic[T, K]):
1155
1154
def test(self) -> T:
1156
1155
pass
1157
1156
1158
1157
def test1(self) -> K:
1159
1158
pass
1160
1159
1160
+ b = B['A', 'A']()
1161
+ y = b.test()
1162
+ z = b.test1()
1163
+
1164
+ class A(Generic[T]):
1165
+ def test(self) -> T:
1166
+ pass
1167
+ " ;
1168
+ var analysis = await GetAnalysisAsync ( code , PythonVersions . LatestAvailable3X ) ;
1169
+ analysis . Should ( ) . HaveVariable ( "b" )
1170
+ . Which . Should ( ) . HaveType ( "B[A, A]" ) ;
1171
+ analysis . Should ( ) . HaveVariable ( "y" )
1172
+ . Which . Should ( ) . HaveType ( "A" ) ;
1173
+ analysis . Should ( ) . HaveVariable ( "z" )
1174
+ . Which . Should ( ) . HaveType ( "A" ) ;
1175
+ }
1176
+
1177
+ [ TestMethod , Priority ( 0 ) ]
1178
+ public async Task GenericClassForwardRefNestedGenerics ( ) {
1179
+ const string code = @"
1180
+ from typing import Generic, TypeVar
1181
+
1182
+ T = TypeVar('T')
1183
+ K = TypeVar('K')
1184
+
1161
1185
a = A['B']()
1162
1186
x = a.test()
1163
1187
1164
- b = B['A', 'A']()
1188
+ b = B['A[int] ', 'A[str] ']()
1165
1189
y = b.test()
1166
1190
z = b.test1()
1191
+
1192
+ class A(Generic[T]):
1193
+ def test(self) -> T:
1194
+ pass
1195
+
1196
+ class B(Generic[T, K]):
1197
+ def test(self) -> T:
1198
+ pass
1199
+
1200
+ def test1(self) -> K:
1201
+ pass
1167
1202
" ;
1168
1203
var analysis = await GetAnalysisAsync ( code , PythonVersions . LatestAvailable3X ) ;
1169
1204
analysis . Should ( ) . HaveVariable ( "a" )
@@ -1172,13 +1207,14 @@ def test1(self) -> K:
1172
1207
. Which . Should ( ) . HaveType ( "B" ) ;
1173
1208
1174
1209
analysis . Should ( ) . HaveVariable ( "b" )
1175
- . Which . Should ( ) . HaveType ( "B[A, A]" ) ;
1210
+ . Which . Should ( ) . HaveType ( "B[A[int] , A[str] ]" ) ;
1176
1211
analysis . Should ( ) . HaveVariable ( "y" )
1177
- . Which . Should ( ) . HaveType ( "A" ) ;
1212
+ . Which . Should ( ) . HaveType ( "A[int] " ) ;
1178
1213
analysis . Should ( ) . HaveVariable ( "z" )
1179
- . Which . Should ( ) . HaveType ( "A" ) ;
1214
+ . Which . Should ( ) . HaveType ( "A[str] " ) ;
1180
1215
}
1181
1216
1217
+
1182
1218
[ TestMethod , Priority ( 0 ) ]
1183
1219
public async Task GenericFunctionArguments ( ) {
1184
1220
const string code = @"
0 commit comments