@@ -5717,6 +5717,17 @@ export function createTypeEvaluator(
5717
5717
case TypeCategory.Class: {
5718
5718
let typeResult: TypeResult | undefined;
5719
5719
5720
+ // If this is a class-like function created via NewType, treat
5721
+ // it like a function for purposes of member accesses.
5722
+ if (
5723
+ ClassType.isNewTypeClass(baseType) &&
5724
+ !baseType.priv.includeSubclasses &&
5725
+ prefetched?.functionClass &&
5726
+ isClass(prefetched.functionClass)
5727
+ ) {
5728
+ baseType = ClassType.cloneAsInstance(prefetched.functionClass);
5729
+ }
5730
+
5720
5731
const enumMemberResult = getTypeOfEnumMember(
5721
5732
evaluatorInterface,
5722
5733
node,
@@ -10279,6 +10290,19 @@ export function createTypeEvaluator(
10279
10290
}
10280
10291
10281
10292
if (isClass(subtype)) {
10293
+ // Specifically handle the case where the subtype is a class-like
10294
+ // object created by calling NewType. At runtime, it's actually
10295
+ // a FunctionType object.
10296
+ if (
10297
+ isClassInstance(subtype) &&
10298
+ ClassType.isNewTypeClass(subtype) &&
10299
+ !subtype.priv.includeSubclasses
10300
+ ) {
10301
+ if (prefetched?.functionClass) {
10302
+ return prefetched.functionClass;
10303
+ }
10304
+ }
10305
+
10282
10306
return convertToInstantiable(stripLiteralValue(subtype));
10283
10307
}
10284
10308
@@ -13512,12 +13536,7 @@ export function createTypeEvaluator(
13512
13536
const initType = FunctionType.createSynthesizedInstance('__init__');
13513
13537
FunctionType.addParam(
13514
13538
initType,
13515
- FunctionParam.create(
13516
- ParamCategory.Simple,
13517
- ClassType.cloneAsInstance(classType),
13518
- FunctionParamFlags.TypeDeclared,
13519
- 'self'
13520
- )
13539
+ FunctionParam.create(ParamCategory.Simple, AnyType.create(), FunctionParamFlags.TypeDeclared, 'self')
13521
13540
);
13522
13541
FunctionType.addParam(
13523
13542
initType,
@@ -13538,7 +13557,7 @@ export function createTypeEvaluator(
13538
13557
const newType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod);
13539
13558
FunctionType.addParam(
13540
13559
newType,
13541
- FunctionParam.create(ParamCategory.Simple, classType , FunctionParamFlags.TypeDeclared, 'cls')
13560
+ FunctionParam.create(ParamCategory.Simple, AnyType.create() , FunctionParamFlags.TypeDeclared, 'cls')
13542
13561
);
13543
13562
FunctionType.addDefaultParams(newType);
13544
13563
newType.shared.declaredReturnType = ClassType.cloneAsInstance(classType);
@@ -24439,6 +24458,15 @@ export function createTypeEvaluator(
24439
24458
}
24440
24459
}
24441
24460
24461
+ // If the source is a class-like type created by a call to NewType, treat it
24462
+ // as a FunctionClass instance rather than an instantiable class for
24463
+ // purposes of assignability. This reflects its actual runtime type.
24464
+ if (isInstantiableClass(srcType) && ClassType.isNewTypeClass(srcType) && !srcType.priv.includeSubclasses) {
24465
+ if (prefetched?.functionClass && isInstantiableClass(prefetched?.functionClass)) {
24466
+ srcType = ClassType.cloneAsInstance(prefetched.functionClass);
24467
+ }
24468
+ }
24469
+
24442
24470
if (recursionCount > maxTypeRecursionCount) {
24443
24471
return true;
24444
24472
}
0 commit comments