Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ export class Binder extends ParseTreeWalker {
// Aliases of "typing" and "typing_extensions".
private _typingImportAliases: string[] = [];

// Aliases of "sys".
private _sysImportAliases: string[] = [];

// Aliases of "dataclasses".
private _dataclassesImportAliases: string[] = [];

Expand Down Expand Up @@ -1583,8 +1580,7 @@ export class Binder extends ParseTreeWalker {
node.d.testExpr,
this._fileInfo.executionEnvironment,
this._fileInfo.definedConstants,
this._typingImportAliases,
this._sysImportAliases
this._currentScope
);
this._nodeInfo.setStaticConditionValue(node, constExprValue);

Expand Down Expand Up @@ -1626,8 +1622,7 @@ export class Binder extends ParseTreeWalker {
node.d.testExpr,
this._fileInfo.executionEnvironment,
this._fileInfo.definedConstants,
this._typingImportAliases,
this._sysImportAliases
this._currentScope
);

const preLoopLabel = this._createLoopLabel();
Expand Down Expand Up @@ -2003,8 +1998,6 @@ export class Binder extends ParseTreeWalker {
if (node.d.module.d.nameParts.length === 1) {
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
this._typingImportAliases.push(node.d.alias?.d.value ?? firstNamePartValue);
} else if (firstNamePartValue === 'sys') {
this._sysImportAliases.push(node.d.alias?.d.value ?? firstNamePartValue);
} else if (firstNamePartValue === 'dataclasses') {
this._dataclassesImportAliases.push(node.d.alias?.d.value ?? firstNamePartValue);
}
Expand Down Expand Up @@ -3301,8 +3294,7 @@ export class Binder extends ParseTreeWalker {
expression,
this._fileInfo.executionEnvironment,
this._fileInfo.definedConstants,
this._typingImportAliases,
this._sysImportAliases
this._currentScope
);
if (
(staticValue === true && flags & FlowFlags.FalseCondition) ||
Expand Down
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,8 @@ export class Checker extends ParseTreeWalker {
evaluateStaticBoolExpression(
node,
this._fileInfo.executionEnvironment,
this._fileInfo.definedConstants
this._fileInfo.definedConstants,
getScopeForNode(node, this._nodeInfo)
) === undefined
) {
let isPossiblyTrue = false;
Expand Down
26 changes: 19 additions & 7 deletions packages/pyright-internal/src/analyzer/dataClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getTypeSourceId,
getTypeVarScopesForNode,
} from './parseTreeUtils';
import { getScopeForNode } from './scopeUtils';
import { evaluateStaticBoolExpression } from './staticExpressions';
import { Symbol, SymbolFlags } from './symbol';
import { isPrivateName } from './symbolNameUtils';
Expand Down Expand Up @@ -388,7 +389,8 @@ export function synthesizeDataClassMethods(
evaluateStaticBoolExpression(
initArg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(initArg.d.valueExpr, nodeInfo)
) ?? includeInInit;
} else {
includeInInit =
Expand All @@ -407,7 +409,8 @@ export function synthesizeDataClassMethods(
evaluateStaticBoolExpression(
kwOnlyArg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(kwOnlyArg.d.valueExpr, nodeInfo)
) ?? isKeywordOnly;
} else {
isKeywordOnly =
Expand Down Expand Up @@ -1391,7 +1394,8 @@ export function validateDataClassTransformDecorator(
const value = evaluateStaticBoolExpression(
arg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(arg.d.valueExpr, nodeInfo)
);
if (value === undefined) {
evaluator.addDiagnostic(
Expand All @@ -1410,7 +1414,8 @@ export function validateDataClassTransformDecorator(
const value = evaluateStaticBoolExpression(
arg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(arg.d.valueExpr, nodeInfo)
);
if (value === undefined) {
evaluator.addDiagnostic(
Expand All @@ -1429,7 +1434,8 @@ export function validateDataClassTransformDecorator(
const value = evaluateStaticBoolExpression(
arg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(arg.d.valueExpr, nodeInfo)
);
if (value === undefined) {
evaluator.addDiagnostic(
Expand All @@ -1448,7 +1454,8 @@ export function validateDataClassTransformDecorator(
const value = evaluateStaticBoolExpression(
arg.d.valueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(arg.d.valueExpr, nodeInfo)
);
if (value === undefined) {
evaluator.addDiagnostic(
Expand Down Expand Up @@ -1569,7 +1576,12 @@ function applyDataClassBehaviorOverride(
nodeInfo: AnalyzerNodeInfoAccessor
) {
const fileInfo = nodeInfo.getFileInfo(errorNode);
const value = evaluateStaticBoolExpression(argValueExpr, fileInfo.executionEnvironment, fileInfo.definedConstants);
const value = evaluateStaticBoolExpression(
argValueExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants,
getScopeForNode(argValueExpr, nodeInfo)
);

applyDataClassBehaviorOverrideValue(evaluator, errorNode, classType, argName, value, behaviors);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/pyright-internal/src/analyzer/namedTuples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Tokenizer } from '../parser/tokenizer';
import { AnalyzerNodeInfoAccessor } from './analyzerNodeInfo';
import { DeclarationType, VariableDeclaration } from './declaration';
import * as ParseTreeUtils from './parseTreeUtils';
import { getScopeForNode } from './scopeUtils';
import { evaluateStaticBoolExpression } from './staticExpressions';
import { Symbol, SymbolFlags } from './symbol';
import { Arg, TypeEvaluator } from './typeEvaluatorTypes';
Expand Down Expand Up @@ -74,7 +75,8 @@ export function createNamedTupleType(
const renameValue = evaluateStaticBoolExpression(
renameArg.valueExpression,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(renameArg.valueExpression, nodeInfo)
);
if (renameValue === true) {
allowRename = true;
Expand Down
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/analyzer/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ export function getTypeOfTernaryOperation(
const constExprValue = evaluateStaticBoolExpression(
node.d.testExpr,
fileInfo.executionEnvironment,
fileInfo.definedConstants
fileInfo.definedConstants,
getScopeForNode(node.d.testExpr, getInfoReader(evaluator))
);

if (constExprValue !== false && evaluator.isNodeReachable(node.d.ifExpr)) {
Expand Down
Loading