Skip to content

Commit

Permalink
Merge tag 'refs/tags/1.1.364' into merge-1.1.364
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/pyright-internal/src/tests/typeEvaluator2.test.ts
#	packages/pyright/package-lock.json
#	packages/pyright/package.json
#	packages/vscode-pyright/package.json
  • Loading branch information
DetachHead committed May 22, 2024
2 parents bd4ce29 + a18387f commit 30e6230
Show file tree
Hide file tree
Showing 276 changed files with 4,912 additions and 1,734 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "1.1.363",
"version": "1.1.364",
"command": {
"version": {
"push": false,
Expand Down
4 changes: 2 additions & 2 deletions packages/pyright-internal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pyright-internal",
"displayName": "pyright",
"description": "Type checker for the Python language",
"version": "1.1.363",
"version": "1.1.364",
"license": "MIT",
"private": true,
"files": [
Expand Down
7 changes: 7 additions & 0 deletions packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3970,6 +3970,13 @@ export class Binder extends ParseTreeWalker {
let finalTypeNode: ExpressionNode | undefined;

if (typeAnnotation) {
// Allow Final to be enclosed in ClassVar. Normally, Final implies
// ClassVar, but this combination is required in the case of dataclasses.
const classVarInfo = this._isAnnotationClassVar(typeAnnotation);
if (classVarInfo?.classVarTypeNode) {
typeAnnotation = classVarInfo.classVarTypeNode;
}

if (this._isTypingAnnotation(typeAnnotation, 'Final')) {
isFinal = true;
} else if (typeAnnotation.nodeType === ParseNodeType.Index && typeAnnotation.items.length === 1) {
Expand Down
23 changes: 19 additions & 4 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3805,8 +3805,7 @@ export class Checker extends ParseTreeWalker {
varType,
filterType,
filterType,
isInstanceCheck,
/* isTypeIsCheck */ false
isInstanceCheck
);
const filterIsSubclass = isIsinstanceFilterSubclass(
this._evaluator,
Expand Down Expand Up @@ -4904,11 +4903,27 @@ export class Checker extends ParseTreeWalker {
];

if (newMemberTypeResult) {
this._evaluator.validateCallArguments(errorNode, argList, newMemberTypeResult);
this._evaluator.validateCallArguments(
errorNode,
argList,
newMemberTypeResult,
/* typeVarContext */ undefined,
/* skipUnknownArgCheck */ undefined,
/* inferenceContext */ undefined,
/* signatureTracker */ undefined
);
}

if (initMemberTypeResult) {
this._evaluator.validateCallArguments(errorNode, argList, initMemberTypeResult);
this._evaluator.validateCallArguments(
errorNode,
argList,
initMemberTypeResult,
/* typeVarContext */ undefined,
/* skipUnknownArgCheck */ undefined,
/* inferenceContext */ undefined,
/* signatureTracker */ undefined
);
}
}
} else if (declaredValueType) {
Expand Down
28 changes: 25 additions & 3 deletions packages/pyright-internal/src/analyzer/codeFlowEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ export function getCodeFlowEngine(
return flowNodeTypeCache;
}

// Determines whether any calls to getTypeFromCodeFlow are pending
// for an expression other than referenceKeyFilter. This is important in cases
// where the type of one expression depends on the type of another
// in a loop. If there are other pending evaluations, we will mark the
// current evaluation as incomplete and return back to the pending
// evaluation.
function isGetTypeFromCodeFlowPending(referenceKeyFilter: string | undefined): boolean {
if (!referenceKeyFilter) {
return false;
}

for (const [key, value] of flowNodeTypeCacheSet.entries()) {
if (key !== referenceKeyFilter && value.pendingNodes.size > 0) {
return true;
}
}

return false;
}

// This function has two primary modes. The first is used to determine
// the narrowed type of a reference expression based on code flow analysis.
// The second (when reference is undefined) is used to determine whether
Expand Down Expand Up @@ -1063,6 +1083,7 @@ export function getCodeFlowEngine(
if (
sawIncomplete &&
!sawPending &&
!isGetTypeFromCodeFlowPending(referenceKeyWithSymbolId) &&
effectiveType &&
!isIncompleteUnknown(effectiveType) &&
!firstAntecedentTypeIsIncomplete
Expand Down Expand Up @@ -1666,9 +1687,10 @@ export function getCodeFlowEngine(
node,
node.arguments,
{ type: callSubtype, isIncomplete: callTypeResult.isIncomplete },
undefined /* typeVarContext */,
false /* skipUnknownArgCheck */,
undefined /* expectedType */
/* typeVarContext */ undefined,
/* skipUnknownArgCheck */ false,
/* inferenceContext */ undefined,
/* signatureTracker */ undefined
);

if (callResult.returnType && isNever(callResult.returnType)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/constraintSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export function assignTypeToTypeVar(
adjWideTypeBound,
newNarrowTypeBound,
diag?.createAddendum(),
typeVarContext,
/* destTypeVarContext */ undefined,
/* srcTypeVarContext */ undefined,
AssignTypeFlags.IgnoreTypeVarScope,
recursionCount
Expand Down
15 changes: 11 additions & 4 deletions packages/pyright-internal/src/analyzer/constructorTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
lookUpObjectMember,
makeInferenceContext,
MemberAccessFlags,
UniqueSignatureTracker,
} from './typeUtils';
import { TypeVarContext } from './typeVarContext';

Expand All @@ -56,10 +57,11 @@ export function applyConstructorTransform(
errorNode: ExpressionNode,
argList: FunctionArgument[],
classType: ClassType,
result: FunctionResult
result: FunctionResult,
signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult {
if (classType.details.fullName === 'functools.partial') {
return applyPartialTransform(evaluator, errorNode, argList, result);
return applyPartialTransform(evaluator, errorNode, argList, result, signatureTracker);
}

// By default, return the result unmodified.
Expand All @@ -71,7 +73,8 @@ function applyPartialTransform(
evaluator: TypeEvaluator,
errorNode: ExpressionNode,
argList: FunctionArgument[],
result: FunctionResult
result: FunctionResult,
signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult {
// We assume that the normal return result is a functools.partial class instance.
if (!isClassInstance(result.returnType) || result.returnType.details.fullName !== 'functools.partial') {
Expand All @@ -92,7 +95,11 @@ function applyPartialTransform(
return result;
}

const origFunctionTypeResult = evaluator.getTypeOfArgument(argList[0]);
const origFunctionTypeResult = evaluator.getTypeOfArgument(
argList[0],
/* inferenceContext */ undefined,
signatureTracker
);
let origFunctionType = origFunctionTypeResult.type;
const origFunctionTypeConcrete = evaluator.makeTopLevelTypeVarsConcrete(origFunctionType);

Expand Down
Loading

0 comments on commit 30e6230

Please sign in to comment.