Skip to content

Commit 9ed33cf

Browse files
authored
Fixed bug that results in a spurious error when running pyright on Python 3.14 but configured for Python 3.13 or earlier. This addresses #11003. (#11006)
1 parent 6e877dd commit 9ed33cf

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { convertOffsetsToRange, convertOffsetToPosition } from '../common/positi
2828
import {
2929
PythonVersion,
3030
pythonVersion3_13,
31+
pythonVersion3_14,
3132
pythonVersion3_6,
3233
pythonVersion3_7,
3334
pythonVersion3_9,
@@ -1021,6 +1022,8 @@ export function createTypeEvaluator(
10211022
// so don't re-enter this block once we start executing it.
10221023
prefetched = {};
10231024

1025+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
1026+
10241027
prefetched.objectClass = getBuiltInType(node, 'object');
10251028
prefetched.typeClass = getBuiltInType(node, 'type');
10261029
prefetched.functionClass = getTypesType(node, 'FunctionType') ?? getBuiltInType(node, 'function');
@@ -1047,7 +1050,15 @@ export function createTypeEvaluator(
10471050
getTypeCheckerInternalsType(node, 'TypedDictFallback') ?? getTypingType(node, '_TypedDict');
10481051
prefetched.awaitableClass = getTypingType(node, 'Awaitable');
10491052
prefetched.mappingClass = getTypingType(node, 'Mapping');
1050-
prefetched.templateClass = getTypeOfModule(node, 'Template', ['string', 'templatelib']);
1053+
1054+
// Don't attempt to resolve the string.templatelib if pyright is configured for
1055+
// Python 3.13 or older. Doing so will either fail to resolve (if running on Python 3.13
1056+
// or older) or resolve to the templatelib.py source file (if running on Python 3.14).
1057+
if (PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion3_14)) {
1058+
prefetched.templateClass = getTypeOfModule(node, 'Template', ['string', 'templatelib']);
1059+
} else {
1060+
prefetched.templateClass = UnknownType.create();
1061+
}
10511062

10521063
prefetched.supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
10531064
if (!prefetched.supportsKeysAndGetItemClass) {

0 commit comments

Comments
 (0)